X = int(input()) def bit_count(n): cnt = 0 while n: cnt += n & 1 n >>= 1 return cnt for i in range(61): N = i ^ X if N <= int(1e18) and bit_count(N) == i: print(N) exit() print(-1)