//--------------------------------------------------template----------------------------------------// //c #include #include #include //c++ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include //c++11 #include #define all(c) ((c).begin(),(c).end()) #define rall(c) (c).rbegin(),(c).rend() //#define sort(v,n) sort(v,v+n) //#define vsort(v) sort(v.begin(),v.end()) //#define vvsort(v) sort(v.begin(),v.end(),greater()) #define ll long long #define pb(a) push_back(a) #define fi first #define se second #define inf 999999999 using namespace std; const ll MOD = 1e9 + 7; const double PI = acos(-1.0); //---------------------------------------------------------------------------------------------// int n; bool b[10001]; int ans = 0; void solve(int a) { if (a == n)return; if (b[a] == 1) { ans = inf; return; } b[a] = 1; ans++; int i = 1; int keta = 1; while (1) { if (i == a)break; if (i > a) { keta--; break; } i *= 2; keta++; } int cont = 0; int aa = a; while (a>0) { if (a / i > 0) { cont++; a %= i; } i /= 2; } if (aa + cont <= n) { solve(aa + cont); } else { solve(aa - cont); } return; } int main() { cin >> n; solve(1); if (ans == inf) { cout << -1 << endl; return 0; } cout << ans+1 << endl; return 0; }