X=int(input()) for i in range(65): N=X^i if bin(N).count('1')==i: print(N) exit() print(-1)