#include<iostream>
#include<algorithm>
#include<cstring>
#include<queue>
using namespace std;
int ans[100001],vis[100001];
queue<int> que;
int bfs(int sp,int ep)
{
que.push(sp);
int i=0,fnp,snp;
ans[sp]=0;
vis[sp]=1;
while(que.size())
{
fnp=que.front();
que.pop();
for(i=0;i<3;i++)
{
if(i==0)
snp=fnp+1;
else if(i==1)
snp=fnp-1;
else
snp=fnp*2;
if(snp<0||snp>100000)
continue;
if(vis[snp]==0)
{
que.push(snp);
ans[snp]=ans[fnp]+1;
vis[snp]=1;
}
if(snp==ep)return ans[ep];
}
}
}
int main()
{
int sp,ep;
while(cin>>sp>>ep)
{
memset(ans,1,100005);
memset(vis,0,100005);
while(!que.empty()) que.pop();
cout<<bfs(sp,ep)<<endl;
}
return 0;
}
#include<algorithm>
#include<cstring>
#include<queue>
using namespace std;
int ans[100001],vis[100001];
queue<int> que;
int bfs(int sp,int ep)
{
que.push(sp);
int i=0,fnp,snp;
ans[sp]=0;
vis[sp]=1;
while(que.size())
{
fnp=que.front();
que.pop();
for(i=0;i<3;i++)
{
if(i==0)
snp=fnp+1;
else if(i==1)
snp=fnp-1;
else
snp=fnp*2;
if(snp<0||snp>100000)
continue;
if(vis[snp]==0)
{
que.push(snp);
ans[snp]=ans[fnp]+1;
vis[snp]=1;
}
if(snp==ep)return ans[ep];
}
}
}
int main()
{
int sp,ep;
while(cin>>sp>>ep)
{
memset(ans,1,100005);
memset(vis,0,100005);
while(!que.empty()) que.pop();
cout<<bfs(sp,ep)<<endl;
}
return 0;
}