#include using namespace std; #ifdef LOCAL #include "settings/debug.cpp" #define _GLIBCXX_DEBUG #else #define Debug(...) void(0) #endif #define rep(i, n) for (int i = 0; i < (n); ++i) using ll = long long; using ull = unsigned long long; int main() { int n; cin >> n; constexpr int INF = 1e9; vector dist(n, INF); dist[0] = 1; queue q; q.push(0); while (!q.empty()) { int v = q.front(); q.pop(); int pp = popcount(ull(v + 1)); for (auto next_v : { v + pp, v - pp }) { if (next_v < 0 || next_v >= n) continue; if (dist[next_v] != INF) continue; dist[next_v] = dist[v] + 1; q.push(next_v); } } cout << (dist[n - 1] == INF ? -1 : dist[n - 1]) << endl; return 0; }