def distance(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 distance(m) < D: l = m else: r = m print(r)