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