#include<bits/stdc++.h>
using namespace std;
int n,m,k=0,d,c,l;
int a[9000001];
struct Node{
	int x,s;
};
queue <Node> q;
int main(){
	cin>>n>>m;
	q.push({n,0});
	if(n==m){
		cout<<0;
		return 0;
	}
	while(q.size()>0){
	 d=q.front().x;
	 c=q.front().s;
	 if(d==m){
	 	cout<<c;
	 	return 0;
	 }
		if(d<=m&&a[d+1]==0) a[d+1]=1,q.push({d+1,c+1});
		if(d>=1&&a[d-1]==0) a[d+1]=1,q.push({d-1,c+1});
		if(d<=m&&a[d*2]==0) a[d+1]=1,q.push({d*2,c+1});
		q.pop();
	}
}
/**************************************************************
	Problem: 2111
	User: zhengzihao
	Language: C++
	Result: Accepted
	Time:59 ms
	Memory:37364 kb
****************************************************************/