/*
分析:
广搜。
2012-07-19
*/
分析:
广搜。
2012-07-19
*/
#include"stdio.h"
#include"string.h"
#include"queue"
using namespace std;
struct node
{
int x;
int step;
};
int map[100011];
int s,e;
int judge(int x)
{
if(x<0 || x>100000) return 1;
if(map[x]) return 1;
return 0;
}
int BFS()
{
queue<node>q;
node cur,next;
cur.x=s;
cur.step=0;
map[cur.x]=1;
q.push(cur);
while(!q.empty())
{
cur=q.front();
q.pop();
if(cur.x==e) return cur.step;
next.x=cur.x+1;
if(judge(next.x)==0)
{
next.step=cur.step+1;
map[next.x]=1;
q.push(next);
}
next.x=cur.x-1;
if(judge(next.x)==0)
{
next.step=cur.step+1;
map[next.x]=1;
q.push(next);
}
next.x=cur.x*2;
if(judge(next.x)==0)
{
next.step=cur.step+1;
map[next.x]=1;
q.push(next);
}
}
return -1;
}
int main()
{
int ans;
while(scanf("%d%d",&s,&e)!=-1)
{
memset(map,0,sizeof(map));
ans=BFS();
printf("%d\n",ans);
}
return 0;
}