x = int(input()) for m in range(62): n = x ^ m if bin(n).count('1') == m: print(n) exit() print(-1)