#include<iostream>
#include <algorithm>
#include<stdlib.h>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include<string.h>
#include<time.h>
using namespace std;
int a[100005],n,m;
int bfs(int n,int m){
memset(a,0,sizeof(a));
queue<int>q;
q.push(n);
a[n]=0;
while(!q.empty()){
int x=q.front();
q.pop();
if(x==m)
return a[x];
if(x+1<=100000&&!a[x+1]){
q.push(x+1);
a[x+1]=a[x]+1;
}
if(x-1>=0&&!a[x-1]){
q.push(x-1);
a[x-1]=a[x]+1;
}
if(x*2<=100000&&!a[2*x]){
q.push(2*x);
a[x*2]=a[x]+1;
}
}
}
int main(){
cin>>n>>m;
cout<<bfs(n,m)<<endl;
return 0;
}