#include using namespace std; int main(){ int N; cin >> N; vector D(N+1, -1); queue Q; D[1] = 1; Q.push(1); while (!Q.empty()){ int n = Q.front(); int b = popcount((unsigned)n); Q.pop(); if (n-b >= 1 && D[n-b] == -1){ Q.push(n-b); D[n-b] = D[n]+1; } if (n+b <= N && D[n+b] == -1){ Q.push(n+b); D[n+b] = D[n]+1; } } cout << D[N] << endl; }