from collections import deque def bitcount(x): return bin(x).count('1') n = int(input()) states = deque([(1, 1)]) searched = {1} while len(states) > 0: pos, turn = states.popleft() if pos == n: print(turn) exit(0) left = pos - bitcount(pos) right = pos + bitcount(pos) if left == n or right == n: print(turn + 1) exit(0) if left not in searched and left > 0: searched.add(left) states.append((left, turn + 1)) if right not in searched and right < n: searched.add(right) states.append((right, turn + 1)) print('-1')