#include using i64 = long long; using u64 = unsigned long long; using u32 = unsigned; using u128 = unsigned __int128; using i128 = __int128; constexpr int inf = 1e9 + 7; void solve() { int N; std::cin >> N; std::vector> adj(N + 1); for(int i = 1; i < N + 1; i ++) { if(i + __builtin_popcount(i) <= N) adj[i].push_back(i + __builtin_popcount(i)); if(i - __builtin_popcount(i) >= 1) adj[i].push_back(i - __builtin_popcount(i)); } std::vector dist(N + 1, inf); std::queue q; q.push(1); dist[1] = 1; while(!q.empty()) { int u = q.front(); q.pop(); if(u == N) break; for(int x : adj[u]) { if(dist[x] == inf) { dist[x] = dist[u] + 1; q.push(x); } } } if(dist[N] == inf) std::cout << -1; else std::cout << dist[N]; } int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int T = 1; //std::cin >> T; while (T--) { solve(); } return 0; }