from collections import * from itertools import * from functools import * from heapq import * import sys,math input = sys.stdin.readline D = int(input()) ans = D def f(k,x): tmp = 0 for i in range(k): tmp += (x//pow(2,i)) return tmp for i in range(1,61): y = D+1 x = 0 while y-x>1: mid = (y+x)//2 if f(i,mid)>=D: y = mid else: x = mid if f(i,y)==D: ans = min(ans,y) print(ans)