#include<iostream>
#include<queue>
using namespace std;
struct node{
int x,num;
};
const int N=100005;
int d;
bool visited[N];
int BFS(int v){
queue<node>q;
node ans,p;
int x;
ans.x=v; ans.num=0;
visited[v]=true;
q.push(ans);
while(!q.empty()){
p=q.front();
q.pop();
x=p.x-1;
if(x<0 || x>N);
else if(!visited[x]){
visited[x]=true;
ans.x=x;
ans.num=p.num+1;
q.push(ans);
if(ans.x==d)
return ans.num;
}
x=p.x+1;
if(x<0 || x>N);
else if(!visited[x]){
visited[x]=true;
ans.x=x;
ans.num=p.num+1;
q.push(ans);
if(ans.x==d)
return ans.num;
}
x=2*p.x;
if(x<0 || x>N);
else if(!visited[x]){
visited[x]=true;
ans.x=x;
ans.num=p.num+1;
q.push(ans);
if(ans.x==d)
return ans.num;
}
}
}
int main(){
int s;
while(cin>>s>>d){
if(s==d){
cout<<0<<endl;
continue;
}
memset(visited,false,sizeof(visited));
cout<<BFS(s)<<endl;
}
//system("pause");
return 0;
}