import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10 ** 7) from collections import deque n = int(readline()) def check(): s = deque([0] * (n + 1)) s[1] = 1 q = deque([1]) while q: v = q.popleft() if v == n: return s[v] bit = bin(v).count('1') v1 = v + bit v2 = v - bit if 0 < v1 <= n and s[v1] == 0: q.append(v1) s[v1] = s[v] + 1 if 0 < v2 <= n and s[v2] == 0: q.append(v2) s[v2] = s[v] + 1 return -1 print(check())