#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
using namespace std;
int a,b;
map<int,map<int,bool>> vis;
map<int,map<int,int>> step;
void bfs(){
queue<pair<int,int>> q;
q.push({a,b});
vis[a][b]=1;
step[a][b]=0;
while(!q.empty()){
int n=q.front().first,m=q.front().second,st=step[n][m];
q.pop();
if(!vis[n*2][m]){
vis[n*2][m]=1;
q.push({n*2,m});
step[n*2][m]=step[n][m]+1;
if(n*2==m){
cout<<step[n][m]+1;
exit(0);
}
}
if(!vis[n][m-1]){
vis[n][m-1]=1;
q.push({n,m-1});
step[n][m-1]=step[n][m]+1;
if(n==m-1){
cout<<step[n][m]+1;
exit(0);
}
}
if(!vis[n][m+1]){
vis[n][m+1]=1;
q.push({n,m+1});
step[n][m+1]=step[n][m]+1;
if(n==m+1){
cout<<step[n][m]+1;
exit(0);
}
}
}
}
int main(){
ios::sync_with_stdio(false);
cin>>a>>b;
if(a==b){
cout<<0;
return 0;
}
bfs();
return 0;
}