BFS
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<queue>
using namespace std;
int N ,K;
typedef pair<int ,int >P;
queue<P>que;
int d[200010];
int bfs()
{
int time=0;
P p;
p.first=N;
p.second=0;
que.push(p);
d[N]=1;
while(que.size())
{
p=que.front();
que.pop();
P t1,t2,t3;
t1.first=p.first+1;
t2.first=p.first-1;
t3.first=p.first*2;
t1.second=t2.second=t3.second=p.second+1;
if(t1.first==K || t2.first==K || t3.first==K )
return p.second+1;
if(t1.first<=K && !d[t1.first])
{
que.push(t1);
d[t1.first]=1;
}
if(t2.first<=K &&!d[t2.first])
{
que.push(t2);
d[t2.first]=1;
}
if(t3.first<=K*2 && !d[t3.first])
{
que.push(t3);
d[t3.first]=1;
}
}
}
void fun()
{
while(que.size())
que.pop();
}
int main()
{
while(scanf("%d%d",&N,&K)!=EOF)
{
memset(d,0,sizeof(d));
if(N>=K)
printf("%d\n",N-K);
else{
fun();
printf("%d\n",bfs());}
}
return 0;
}