#include<bits/stdc++.h>
using namespace std;
int n,m;
struct nf{
int x,t;
}que[100010];
int f,r;
int book[100010]={0};
void move(int nx,int y){
if(nx>=0 && nx<=100000 && book[nx]==0){
book[nx]=1;
r++;
que[r].x=nx;
que[r].t=y+1;
}
}
int main(){
cin>>n>>m;
f=r=1;
que[r].x=n , que[r].t=0;
while(f<=r){
int fx,ft;
fx=que[f].x , ft=que[f].t;
if(fx==m){
cout<<ft<<endl;
break;
}
move(fx-1,ft);
move(fx+1,ft);
move(fx*2,ft);
f++;
}
return 0;
}