d = int(input()) ans = d res = d // 2 for val in range(d // 2, d // 2 + 1000000): val0 = val tmp = val val = val >> 1 while val: tmp += val if tmp == d: ans = min(ans, val0) break val = val >> 1 print(ans)