from collections import deque def bfs(start, end): visited = [] queue = deque([start]) while queue: v = queue.popleft() visited.append(v) if v == end: return visited for n in g[v]: if n not in visited: queue.append(n) break return None N = int(input()) m = [] g = {} for i in range(1, N + 1): m.append("{:b}".format(i).count("1")) for i in range(len(m)): l = [] if i + m[i] < len(m): l.append(i + m[i]) if i - m[i] >= 0: l.append(i - m[i]) g[i] = l path = bfs(0, N - 1) if path: print(len(path))