include[HTML_REMOVED]
include[HTML_REMOVED]
include[HTML_REMOVED]
using namespace std;
const int N = 2e5+10;
int q[N], front, rear;
int dis[N];
int n, k;
void bfs(int x){
q[rear++]=x;
dis[x]=0;
while(front<rear){
int p = q[front];
front++;
if(p==k) {
return;
}
//p-1
if( p-1>=0 && dis[p-1]==-1){
dis[p-1]=dis[p]+1;
q[rear++]=p-1;
}
//p+1
if( p+1<N && dis[p+1]==-1){
dis[p+1]=dis[p]+1;
q[rear++]=p+1;
}
//p*2
if( p*2<N && dis[p*2]==-1){
dis[p*2]=dis[p]+1;
q[rear++]=p*2;
}
}
}
int main(){
// freopen(“niu.in”,”r”,stdin);
// freopen(“niu.out”,”w”,stdout);
memset(dis, -1, sizeof(dis));
cin >> n >> k;
bfs(n);
cout << dis[k];
return 0;
}