from collections import deque N = int(input()) dp = [N + 1] * N dp[0] = 1 distances = [0] * N for i in range(N): num = i + 1 distance = 0 while num > 0: distance += num & 1 num = num >> 1 distances[i] = distance q = deque() q.append(0) i = 0 while len(q) > 0: i = q.pop() num = i + 1 back = i - distances[i] front = i + distances[i] if back >= 0 and dp[back] > dp[i] + 1: dp[back] = dp[i] + 1 q.append(back) if front < N and dp[front] > dp[i] + 1: dp[front] = dp[i] + 1 q.append(front) if dp[N - 1] == N + 1: print(-1) else: print(dp[N - 1])