#include #include #include #include #include #include using namespace std; int n; int field[10001]; int cnt1(int n){ int result = 0; while(n){ if(n & 1) result += 1; n >>= 1; } return result; } int solve(int now, int depth){ if(now < 1 || now > n) return -1; if(now == n){ return depth; } if(field[now] == -1 || field[now] >= depth) { field[now] = depth; int s1 = solve(now + cnt1(now), depth + 1); int s2 = solve(now - cnt1(now), depth + 1); if(s1 == -1) return s2; if(s2 == -1) return s1; return min(s1, s2); }else{ return -1; } } int main(){ cin >> n; for(int i = 0; i < n; i++){ field[i] = -1; } cout << solve(1, 1) << endl; }