popcount = lambda x: bin(x).count("1") def solve(X): for m in range(64): n = X ^ m if popcount(n) == m: return n return -1 print(solve(int(input())))