#include<bits/stdc++.h>
using namespace std;
int n,m,a[5000001];
struct Node{
	int x,step;
};
queue<Node> q;

int main(){
	
//	freopen("test8.in","r",stdin);
//	freopen("ans8.out","w",stdout);
	
	cin>>n>>m;//5 17
	q.push({n,0});
	while(!q.empty()){
		int x=q.front().x;
		int step=q.front().step;
		if(x==m){
			cout<<step;
			return 0; 
		}
		if(x<=m&&a[x+1]==0)  a[x+1]=1,q.push({x+1,step+1});	
		if(x>=1&&a[x-1]==0) 	a[x-1]=1,q.push({x-1,step+1});
		if(x<=m&&a[x*2]==0) 	a[x*2]=1,q.push({x*2,step+1});
		
		q.pop();
	} 
	
	
	return 0;
}

/**************************************************************
	Problem: 2111
	User: hulaoshi
	Language: C++
	Result: Accepted
	Time:60 ms
	Memory:21608 kb
****************************************************************/