mod = 1000000007 eps = 10**-9 def main(): import sys input = sys.stdin.readline X = int(input()) for M in range(62): N = X ^ M cnt = 0 for i in range(62): cnt += N >> i & 1 if cnt == M: if N <= 2 * 10 ** 18: print(N) exit() print(-1) if __name__ == '__main__': main()