def popcount(n): cnt = 0 while n: cnt += n & 1 n //= 2 return cnt X = int(input()) for i in range(65): N = X ^ i if popcount(N) == i and N: print(N) exit() print(-1)