#include <iostream>
#include <vector>
#include <queue>
using namespace std;
const int N=20000;

vector<int> adj[N];
int odl[N];



void bfs(int n){
	
	
	for(int i=0; i<N; i++)
	odl[i]=-1;
	odl[n]=0;
	
	queue<int> kol;
	kol.push(n);
	while(!kol.empty()){
		int a=kol.front();
		kol.pop();
		for(int o: adj[a]){
			if(odl[o]==-1){
			odl[o]=odl[a]+1;
			kol.push(o);}
		}
		
		
		
		
		
	}
	
	
}



int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	int n,m;
	cin>>n>>m;
	for(int i=1; i<2*max(m,n); i++)
	{
	
		adj[i].push_back(2*i);
		adj[i].push_back(i-1);}
	
	
	bfs(n);
	
	cout<<odl[m]<<" ";
	
	
	return 0;
}