#include #include #include using namespace std; static int count_bits(int i) { auto b = 0; while (i > 0) { if (i & 0x01) ++b; i >>= 1; } return b; } static int move(const vector& bits, int n, int pos, int count) { if (n == pos) return count; if (count > 1 && pos <= 1) return -1; if (pos + bits[pos] > n) return move(bits, n, pos - bits[pos], count + 1); return move(bits, n, pos + bits[pos], count + 1); } static void run() { int n; cin >> n; vector bits; bits.resize(n + 1); for (auto i = 1; i <= n; ++i) { bits[i] = count_bits(i); } const auto count = move(bits, n, 1, 1); cout << count << endl; } int main(int argc, char **argv) { run(); return 0; }