x = int(input()) def popcount(x): res = 0 while x > 0: if x % 2 == 1: res += 1 x //= 2 return res for i in range(70): if popcount(i ^ x) == i and (i ^ x) <= 2 * (10 ** 18): print(i ^ x) exit(0) print(-1)