/* BFS */
#include<iostream>
#include<cstdio>#include<queue>
#include<cstring>
using namespace std;
int vis[100005];
queue <int> q;
int bfs(int x, int y)
{
while(!q.empty())
q.pop();
q.push(x);
vis[x]=1;
if(x==y) return 0;
while(!q.empty())
{
if( vis[x+1]==0 &&(x+1)<=100000 )
{
q.push(x+1);
vis[x+1]=vis[q.front()]+1;
}
if( (x-1)>=0 && vis[x-1]==0 )
{
q.push(x-1);
vis[x-1]=vis[q.front()]+1;
}
if(x*2<=100000&& vis[x*2]==0 )
{
q.push(x*2);
vis[x*2]=vis[q.front()]+1;
}
q.pop();
x=q.front();
if(x==y) return vis[x]-1;
}
}
int main()
{
int a,b;
while(~scanf("%d%d",&a,&b))
{
memset(vis,0,sizeof(vis));
cout<<bfs(a,b)<<endl;
}
return 0;
}