#include #include #include #include #include #include #include #include #include using namespace std; int main() { long N; cin >> N; queue> q; q.push(make_pair(1, 0)); long count = -1; while (!q.empty()) { auto p = q.front(); q.pop(); if (p.first == N) { count = p.second; break; } if ((p.first - 1) >= 1) { q.push(make_pair(p.first - 1, p.second + 1)); } if ((p.first * 2) <= 1e9) { q.push(make_pair(p.first * 2, p.second + 1)); } } cout << count << "\n"; }