N = int(input()) moves = [bin(x).count('1') for x in range(N+1)] routes = [] def move(now, route): route.add(now) if now == N: routes.append(len(route)) print(route) else: back, go = -1 * moves[now] + now, moves[now] + now for target in [back, go]: if (1 < target <= N) and (target not in route): move(target, route.copy()) move(1, set()) if len(routes) == 0: print(-1) # unreachable else: print(max(routes))