X = int(input()) found = -1 for m in range(1, 61): n = X ^ m if 1 <= n <= 2 * 10**18: if bin(n).count('1') == m: found = n break print(found)