#include<iostream>
#include<cstdio>
#include<queue>
using namespace std;
const int N = 1e6 + 10;
struct node
{
int now, dis;
};
int n, vis[N];
void bfs(int x, int y)
{
queue <node> q;
q.push((node){x, y});
while (!q.empty())
{
int sx = q.front().now, sy = q.front().dis;
q.pop();
if (vis[sx] || sx < 1 || sx > n) continue;
vis[sx] = 1;
if (sx == n)
{
printf("%d", sy);
return ;
}
q.push((node){sx - 1, sy + 1});
q.push((node){sx + 1, sy + 1});
q.push((node){2 * sx, sy + 1});
}
}
int main()
{
scanf("%d", &n);
bfs(1, 0);
return 0;
}