# Arup Guha
# 3/17/2026
# Solution to 2026 UCF HS Contest Problem C: Take a Pancake

# Sequence of losing states for the person going first.
# Also, these values are of the form 2*(2**i-1)
''' The thinking here is that you can't win at 2. Then you can
    get to 2 from 3, 4 or 5, so the next state you can't win from is 6
    more generally, if x is a losing state for the first person then
    2x+2 is the next losing state for that person. '''
seq = [2]
x = 2
while x < 10**10:
    x = 2*x + 2
    seq.append(x)

# Get input.
n = int(input())

# This is fast enough...
i = 0
while seq[i] < n:
    i+=1

# Ta da!
print(seq[i]-n)
