#include using namespace std; typedef pair P; const int IINF = INT_MAX; const int MAX_N = int(1e5) + 5; #define FOR(i, m, n) for (int i = m; i < n; i++) vector g[MAX_N]; int n, d[MAX_N]; void bfs() { fill(d, d + n + 1, -1); queue

que; d[1] = 1; que.push({1, 1}); while (!que.empty()) { P p = que.front(); que.pop(); int v = p.first; for (auto u : g[v]) { if (d[u] == -1) { d[u] = p.second + 1; que.push({u, d[u]}); } } } } int main() { cin >> n; FOR(i, 1, n + 1) { int cnt = 0; FOR(j, 0, (1 << j)) { if (i & (1 << j)) cnt++; } if (i + cnt <= n) g[i].push_back(i + cnt); if (i - cnt > 0) g[i].push_back(i - cnt); } bfs(); cout << d[n] << endl; return 0; }