#include #include #include #include #include #include using namespace std; typedef uint uint32_t; int f(int N) { queue q; q.push(1); int count[10001] = {0}; count[1] = 1; while (q.size() > 0) { int n = q.front(); // cout << n << endl; q.pop(); if (n == N) return count[n]; int bc = __builtin_popcount(n); int n1 = n + bc; int n2 = n - bc; if (0 < n1 && n1 <=N && count[n1] == 0) { count[n1] = count[n] + 1; q.push(n1); } if (0 < n2 && n2 <=N && count[n2] == 0) { count[n2] = count[n] + 1; q.push(n2); } } return -1; } int main() { int N; cin >> N; cout << f(N) << endl; return 0; }