X = int(input()) if X==0: print(1) exit() for i in range(100): if (X>>i)&1: msb = i for M in range(msb+10): N = X^M M2 = 0 for i in range(100): if (N>>i)&1: M2 += 1 if M==M2: print(N) exit() print(-1)