X = int(input()) for M in range(63): if bin(X ^ M).count('1') == M: exit(print(X ^ M)) print(-1)