#include <iostream>
#include <queue>
using namespace std;
//抄博友程序
int vis[100008];
struct nod{
int x,d;
nod(int a,int b)
{
x=a;
d=b;
}
};
int main()
{
int N,K;
cin>>N>>K;
queue<nod> que;
nod t(N,0);
que.push(t);
vis[N]=1;
int jg;
while(que.empty()!=1)
{
nod t=que.front();
//cout<<t.x<<" "<<t.d<<endl;
if(K==t.x)
{
jg=t.d;
break;
}
que.pop();
if(t.x>0 && vis[t.x-1]==0)
{
nod w(t.x-1,t.d+1);
que.push(w);
vis[t.x-1]=1;
}
if(t.x<100000 && vis[t.x+1]==0)
{
nod w(t.x+1,t.d+1);
que.push(w);
vis[t.x+1]=1;
}
if((t.x*2)<=100000 && (t.x*2)>=0 && vis[(t.x)*2]==0)
{
nod w((t.x)*2,t.d+1);
que.push(w);
vis[(t.x)*2]=1;
}
}
cout<<jg<<endl;
return 0;
}