#include <iostream>
#include <queue>
#include <cstring>
using namespace std;
const int maxn=100001;
int step[maxn]; //用来标记每一个点走了多少步到达
int vis[maxn]; //判断是否寻找过
queue<int > q;
int bfs(int n,int k)
{
q.push(n);
int head,next;
step[n]=0;
vis[n]=1;
while(!q.empty())
{
head=q.front();
q.pop();
for(int i=0;i<3;i++)
{
if(i==0)
next=head+1;
else if(i==1)
next=head-1;
else if(i==2)
next =head*2;
if(next<0 ||next>=maxn)
continue;
if(!vis[next])
{
q.push(next);
vis[next]=1;
step[next]=step[head]+1;
}
if(next==k)
{
return step[next];
}
}
}
}
int main()
{
int n,k;
while(cin>>n>>k)
{
memset(step,0,sizeof step);
memset(vis,0,sizeof vis);
while(!q.empty()) q.pop();
if(n>=k)
cout<<n-k<<endl;
else
cout<<bfs(n,k)<<endl;
}
return 0;
}