x=int(input()) if x==0: print(1) exit() for i in range(70): y=x^i if bin(y).count('1')==i: print(y) exit() print(-1)