D = int(input()) ok = pow(10,18)*2 ng = 0 def check(x): ret = x while x > 0: x = x//2 ret += x return ret cnt = 0 while abs(ok-ng) > 1: #and cnt < 100: mid = (ok+ng)//2 #print(ok,mid,ng) if check(mid) >= D: ok = mid else: ng = mid cnt += 1 ans = ok #print(ans) def verify(x,y): ret = x while x > 0: if ret == y: return True else: x = x//2 ret += x if ret == y: return True else: return False while True: if verify(ans,D): print(ans) break else: ans += 1