#include<iostream>
#include<queue>
using namespace std;
long long n;
struct j{
long long idx,step;
};
int bfs(int n){
long long l,s,mins=n+1;
queue<j>q;
j z;
z.idx=1;
z.step=0;
q.push(z);
while(!q.empty()){
l=q.front().idx;
s=q.front().step;
q.pop();
if(l==n){
mins=min(mins,s);
cout<<mins;
continue;
}if((l-1)>0&&(l-1)<=n){
z.idx=l-1;
z.step=s+1;
q.push(z);
}if((l+1)>0&&(l+1)<=n){
z.idx=l+1;
z.step=s+1;
q.push(z);
}if((l*2)>0&&(l*2)<=n){
z.idx=l*2;
z.step=s+1;
q.push(z);
}
}
return mins;
}
int main(){
cin>>n;
cout<<bfs(n);
}