from collections import deque def bit_count(n): cnt = 0 while 0 < n: n &= n-1 cnt += 1 return cnt def main(): """ main """ N = int(input()) dp = set() dp.add(1) q = deque([(1, 1)]) # queueが空になるまでloopを回し、到達すればbreak and return while q: pos, cnt = q.popleft() if pos == N: print(cnt) break step = bit_count(pos) if 1 < (pos - step) and pos-step not in dp: dp.add(pos-step) q.append((pos-step, cnt+1)) if (pos + step) <= N and pos + step not in dp: dp.add(pos+step) q.append((pos+step, cnt+1)) else: print(-1) main()