from collections import deque def solve(N): q = deque([1]) dist = [float("INF")]*(N+1) dist[1] = 1 while q: cur = q.popleft() if cur == N: return dist[N] d = dist[cur] mv = cur.bit_count() if 1 <= cur+mv <= N and d+1 < dist[cur+mv]: q.append(cur+mv) dist[cur+mv] = d+1 if 1 <= cur-mv <= N and d+1 < dist[cur-mv]: q.append(cur-mv) dist[cur-mv] = d+1 return -1 N = int(input()) print(solve(N))