""" Mは高々30ぐらい """ import sys from sys import stdin def popcnt(a): ret = 0 while a > 0: ret += a % 2 a //= 2 return ret X = int(stdin.readline()) for i in range(40): N = X ^ i if popcnt(N) == i: print (N) sys.exit() print (-1)