#include #define rep(i, n) for (int i = 0; i < n; ++i) typedef long long ll; using namespace std; int main() { int N; cin >> N; int ans = 1; int now = 1; set st; while (now != N && st.find(now) == st.end()) { st.insert(now); int diff = __builtin_popcount(now); if (now + diff <= N) now += diff; else now -= diff; ans++; } if (now == N) cout << ans; else cout << -1; cout << endl; return 0; }