#include <iostream>
#include <cstring>
#include <algorithm>
#include <queue>
using namespace std;
int vis[2000005];
int n;
void bfs()
{
queue<int> q;
q.push(n);
vis[n] = 0;
while (!q.empty())
{
int now = q.front();
q.pop();
if (now == n) return;
int nxt = now + 1;
if (1 <= nxt && nxt <= n && vis[nxt] == -1)
{
q.push(nxt);
vis[nxt] = vis[now] + 1;
}
nxt = now - 1;
if (1 <= nxt && nxt <= n && vis[nxt] == -1)
{
q.push(nxt);
vis[nxt] = vis[now] + 1;
}
nxt = now * 2;
if (1 <= nxt && nxt <= n && vis[nxt] == -1)
{
q.push(nxt);
vis[nxt] = vis[now] + 1;
}
}
}
int main()
{
cin >> n;
memset(vis, -1, sizeof vis);
bfs();
cout << vis[n];
return 0;
}
必关必关!!!