import math def pop_count(k): count = 0 for i in range(k.bit_length()): if k >> i & 1 == 1: count += 1 return count x = int(input()) if x != 0 and x != 1 and x != 2: for m in range(math.ceil(math.log2(x))+1): n = m ^ x if pop_count(n) == m: print(n) break else: print(-1) else: if x == 2: print(-1) elif x == 1: print(3) else: print(1)