D=int(input()) L=D//2 R=D while L!=R: now=(L+R)//2 count=0 while now>0: count+=now now//=2 if count>=D: R=(L+R)//2 else: L=(L+R)//2+1 ok=0 for _ in range(10**7): count=0 now=L while count0: count+=now now//=2 if count==D: ok=1 break L+=1 print(L if ok else D)