def popcount(x): return bin(x).count("1") X=int(input()) N=-1 for M in range(65): if 1<=X^M<=2*10**18 and popcount(X^M)==M: N=X^M print(N)