#include #include // #include using namespace std; #define INF 10000000 void next(int k, vector &dp, int count, int n) { int step = 0; if (dp[k] < INF) return; dp[k] = count; count++; for (int i = k; i > 0; i = i >> 1) { if(i & 1) step++; } if (k + step <= n) next(k + step, dp, count, n); if (k - step >= 1) next(k - step, dp, count, n); } int main() { int n; cin >> n; vector dp(n+1, INF); int count = 1; next(1, dp, 1, n); if (dp.at(n) < INF) cout << dp.at(n) << endl; else cout << -1 << endl; return 0; }