from collections import deque def convert_bit(x): return bin(x).count("1") N = int(input()) q = deque([1]) reach =[0 for i in range(N)] while q != deque([]): pos = q.popleft() reach[pos-1] = 1 if pos == N: print(N) exit() move = convert_bit(pos) for m in [move,-move]: next_pos = m + pos if not 1 <= next_pos <= N: continue if reach[next_pos - 1] == 1: q.append(next_pos) print(-1)