#include using namespace std; int bitcount(int N){ int i,j,k; i = 0; k = 0; while(pow(2,i) <= N){ i++; } j = i - 1; while(N != 0){ k += N / (int)pow(2,j); N = N % (int)pow(2,j); j--; } return k; } int main(){ int i,a[100000],b[100000]; int N; int m1,m2; int q; for(i=0;i<100000;i++){ a[i] = -1; b[i] = 0; } cin >> N; queue que; que.push(1); a[1] = 1; b[1] = 1; while(que.size() != 0){ q = que.front(); que.pop(); m1 = q - bitcount(q); m2 = q + bitcount(q); if(m1 > 0 && b[m1] != 1){ que.push(m1); b[m1] = 1; a[m1] = a[q] + 1; } if(m2 > 0 && b[m2] != 1){ que.push(m2); b[m2] = 1; a[m2] = a[q] + 1; } } cout << a[N] << endl; return 0; }