#include using namespace std; int bin(int n) { int r = 0; while(n){ r += n % 2; n /= 2; } return r; } int main() { int n; cin >> n; vector v(n+1,1); queue que; que.push(1); while(que.size()){ int x = que.front(),y = bin(x); que.pop(); if(0 < x + y && x + y <= n && v[x+y] == 1){ que.push(x+y); v[x+y] = v[x] + 1; } if(x + y == n){ cout << v[x+y] << endl; return 0; } if(0 < x - y && x - y <= n && v[x-y] == 1){ que.push(x-y); v[x-y] = v[x] + 1; } if(x - y == n){ cout << v[x-y] << endl; return 0; } } cout << "-1" << endl; return 0; }