import math ma = int(input()) mi = ma//2 x = 0 while True: x = 0 for p in range(60): temp = math.floor(mi*(1/2)**p) if temp >= 1 and ma - x <= 2*temp: x += temp if x == ma: print(mi) exit() else: mi += 1 break