#include #include #include #include #include #include #include #include #include #include using ll = long long; using namespace std; int main(){ int n, now = 1; cin >> n; set st; while (now != n){ int tmp, cnt = 0; if (st.count(now)){ cout << -1 << endl; return 0; } st.insert(now); tmp = now; while (tmp){ if (tmp &1) cnt++; tmp >>= 1; } if (now + cnt == n){ st.insert(n); break; } else if (now + cnt > n) now -= cnt; else now += cnt; } cout << st.size() << endl; }