#include "bits/stdc++.h" using namespace std; int N, Dist[10010], INF = 1000000000; int main() { cin >> N; for (int i = 1; i <= N; i++) Dist[i] = INF; Dist[1] = 1; queue Q; Q.push(1); while (!Q.empty()) { int X = Q.front(); Q.pop(); if (X == N) { cout << Dist[X] << endl; return 0; } int _X= X, Y = 0; while (_X != 0) Y += _X % 2, _X /= 2; if (X - Y >= 1) { if (Dist[X - Y] == INF) { Dist[X - Y] = Dist[X] + 1; Q.push(X - Y); } } if (X + Y <= N) { if (Dist[X + Y] == INF) { Dist[X + Y] = Dist[X] + 1; Q.push(X + Y); } } } cout << -1 << endl; }