ans=True x=int(input()) for i in range(100): y=x^i if bin(y).count("1")==i: ans=False print(y) break if ans: print(-1)