x=int(input()) for m in range(63): n=x^m if n.bit_count()==m and 1<=n<=2*10**18: print(n) exit() print(-1)