def popcount(x): return bin(x)[2:].count("1") x = int(input()) for i in range(64): if popcount(i ^ x) == i and i ^ x > 0: print(i ^ x) break else: print(-1)