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