d = int(input()) ng = 0 ok = d def cal(a): cnt = 0 while a: cnt += a a//=2 return cnt def cal2(a): cnt = 0 while a: cnt += a a//=2 if cnt == d: return True return False ans = d while ok - ng > 1: mid = (ok + ng)//2 if cal(mid) >= d: ok = mid else: ng = mid if cal2(mid): ans = min(ans,mid) print(ans)