#yuki1450 x=int(input()) if x==0: print(1) exit() for m in range(65): n=x^m if bin(n).count('1')==m: print(n) exit() print(-1)