chatr=int(input())
gr=[]
dog=0
for h in range (0,chatr+1):
    dog=abs((2**h)-chatr)
    gr.append(dog)
kall=min(gr)
print(kall)

bd10b220cc1fcd76fc515d0efdc831f318847a6f
<mask token>

<mask token>
for h in range(0, chatr + 1):
    dog = abs(2 ** h - chatr)
    gr.append(dog)
<mask token>
print(kall)

chatr = int(input())
gr = []
dog = 0
for h in range(0, chatr + 1):
    dog = abs(2 ** h - chatr)
    gr.append(dog)
kall = min(gr)
print(kall)

chatr=int(input())
gr=[]
dog=0
for h in range (0,chatr+1):
    dog=abs((2**h)-chatr)
    gr.append(dog)
kall=min(gr)
print(kall)
