#include using namespace std; int N,w[10001],c = 0; bool e[10001]; queue Qu; int main(){ cin >> N; for(int i = 1; i <= N; i++) e[i] = false; for(int i = 1; i <= N; i++){ int tw = 1; int t = i; while(t != 1){ if(t%2) tw++; t /= 2; } w[i] = tw; } Qu.push(1); while(true){ if(Qu.empty()){ cout << -1 << endl; return 0; } int t = Qu.front(); Qu.pop(); c++; if(t == N){ cout << c << endl; return 0; } if(t + w[t] <= N && !e[t + w[t]]){ Qu.push(t + w[t]); e[t + w[t]] = true; }else if(t - w[t] >= 0 && !e[t - w[t]]){ Qu.push(t - w[t]); e[t - w[t]] = true; } } }