#include #include #include using namespace std; const int INF = 1e+9; int main() { cin.tie(0); ios::sync_with_stdio(false); int n; cin >> n; int ans = -1; queue que; que.push(1); bool visited[10001] = {0}; int d[10001] = {0}; d[1] = 1; while(!que.empty()){ int p = que.front(); que.pop(); if(n == p){ ans = d[p]; break; } if(visited[p]){ continue; } visited[p] = true; int next = __builtin_popcount(p); if(next + p <= n){ d[next + p] = d[p] + 1; que.push(next + p); } } cout << ans << endl; return 0; }