x = int(input()) for i in range(1, 65): n = x ^ i if bin(n).count("1") == i: print(n) break else: print(-1)