import sys input = lambda : sys.stdin.readline().rstrip() sys.setrecursionlimit(max(1000, 10**9)) write = lambda x: sys.stdout.write(x+"\n") d = int(input()) def sub(x): v = x while x>0: x = x//2 v += x return v>=d def val(x): v = x while x>0: x = x//2 v += x if v==d: return v return v l = 0 r = d while ld: r -= 1 if val(r)==d: print(r) else: print(d)