#include<bits/stdc++.h>
using namespace std;
long long mp[1000005],n,ans = 0,bushu[1000005];
long long move(int a,int x)
{
if(a == 1)
{
return x - 1;
}
else if(a == 2)
{
return x + 1;
}
else
{
return 2 * x;
}
}
int bfs(long long a)
{
queue<long long> q;
q.push(a);
mp[a] = 1;
while(!q.empty())
{
ans++;
long long u = q.front();
q.pop();
long long xx;
for(int i = 1;i <= 3;i++)
{
xx = move(i,u);
if(xx < 1|| mp[xx] == 1||xx > n)
{
continue;
}
mp[xx] = 1;
bushu[xx] = bushu[u] + 1;
q.push(xx);
if(xx == n)
{
return 1;
}
}
}
return 0;
}
int main()
{
cin >> n;
int check;
check = bfs(1);
cout << bushu[n] << endl;
return 0;
}