X=int(input()) for i in range(65): N=X^i if N==0: continue if N.bit_count()==i: print(N) exit() print(-1)