def distance(L,D): res = 0 v = L while L: res += L L //= 2 if res == D: return True return False def sdistance(L): res = 0 v = L while L: res += L L //= 2 return res D = int(input()) l = 0 r = 10**18 while r - l > 1: m = (r + l)//2 if sdistance(m) < D: l = m else: r = m for i in range(l,l + 1000000): if distance(i,D): print(i) exit()