from collections import deque def bitCount(n): count = 0 while n > 0: n = n & (n - 1) count += 1 return count def bfs(N): table = [0] * (N + 1) q = deque() q.append(1) table[1] = 1 while len(q) > 0: current = q.popleft() if current == N: return table[current] a = current + bitCount(current) b = current - bitCount(current) if 1 <= a <= N and table[a] == 0: q.append(a) table[a] = table[current] + 1 if 1 <= b <= N and table[b] == 0: q.append(b) table[b] = table[current] + 1 return -1 N = int(raw_input()) print (bfs(N))