#include using namespace std; int main() { int N; cin >> N; vector> G(N); for (unsigned int i = 1; i <= N; i++) { int bit_count = popcount(i); int pre = i - bit_count; int next = i + bit_count; if (pre >= 1) { G[i - 1].push_back(pre - 1); } if (next <= N) { G[i - 1].push_back(next - 1); } } vector visited(N); auto dfs = [&](auto dfs, int v, int ans = 0) { ans++; if (v == N - 1) { cout << ans; exit(0); } if (visited[v]) { return; } visited[v] = true; for (auto nv : G[v]) { dfs(dfs, nv, ans); } }; dfs(dfs, 0); cout << -1; }