N = int(input()) visited = [0] * N def bfs(visited, now, ans): if now == (N - 1): return ans if sum(visited) == N: return -1 visited[now] = 1 tmp = bin(now + 1) count = 0 for i in tmp: if i == '1': count += 1 if now + count < N and visited[now + count] == 0: return bfs(visited, now + count, ans + 1) if 0 < now - count and visited[now - count] == 0: return bfs(visited, now - count, ans + 1) return -1 print(bfs(visited, 0, 1))