X = int(input()) ans = -1 for N in range(X-500,X+500): if X == N ^ format(N, 'b').count('1'): ans = N print(ans)