ans=True x=int(input()) if x==0: print(-1) else: for i in range(120): y=x^i if bin(y).count("1")==i and y<=2*10**18: ans=False print(y) break if ans: print(-1)