#include <bits/stdc++.h>
using namespace std;
const int N=1e7;
typedef pair<int,int> PII;
bool st[N];
int main(){
int n;
cin>>n;
queue<PII> q;
q.push({1,0});
while(!q.empty())
{
auto t=q.front();
q.pop();
int node=t.first;
st[node]=true;
int step=t.second;
if(node == n)
{
cout<<step;
return step;
}
if( 1+node >= 1 && node+1 <=n && !st[node+1])
q.push({node+1,step+1});
if( 2*node >= 1 && node*2 <=n && !st[node*2])
q.push({node*2,step+1});
}
return 0;
}