#include using namespace std; int main(){ int n; int i; cin >> n; deque que; que.push_back(1); int dist[n+1]; for(i=0;i<=n;i++)dist[i] = -1; dist[1] = 1; while(!que.empty()){ int now = que.front(); que.pop_front(); int b = __builtin_popcount(now); int d = dist[now]; if(now-b >= 0 && dist[now-b] == -1){ dist[now-b] = d+1; que.push_back(now-b); } if(now+b <= n && dist[now+b] == -1){ dist[now+b] = d+1; que.push_back(now+b); } } cout << dist[n] << endl; }