from collections import deque N = int(input()) dist = [-1]*(N + 1) dist[1] = 1 que = deque() que.append(1) while que: pos = que.popleft() b = pos.bit_count() for j in [-b, b]: nex = pos + j if 1 <= nex <= N and dist[nex] == -1: dist[nex] = dist[pos] + 1 que.append(nex) print(dist[-1])