#include<bits/stdc++.h>
using namespace std;
int n,k,co[200010];
int bfs()
{
queue<int> q;
q.push(n);
while(!q.empty())
{
int c=q.front();
q.pop();
if(2*c==k||c+1==k||c-1==k)return co[c]+1;
if(2*c<=2e5&&co[2*c]==0&&2*c!=n&&2*c<=2*k){co[2*c]=co[c]+1;q.push(2*c);}
if(co[c+1]==0&&c+1!=n&&c+1<=2*k){co[c+1]=co[c]+1;q.push(1+c);}
if(co[c-1]==0&&c-1!=n&&c-1<=2*k&&c-1>0){co[c-1]=co[c]+1;q.push(c-1);}
}
}
int main()
{
cin>>n>>k;
if(n>=k)cout<<n-k;
else cout<<bfs();
}
只要一个数组记录到该位置的最短步数,新位置不是初始位置且该位置为对应步数为0(未访问过),就可以啦