#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll x,y,res;
map<ll,ll>mp;            //将a变成b需要的步数 
ll dfs(ll k){
	if(k<=x) return x-k;             //-1 使x变小 
	if(mp[k]) return mp[k];
	ll cnt=k-x;                     //k>x
	if(!(k&1)) cnt=min(cnt,dfs(k/2)+1);       //1步 *2的操作
	else cnt=min(cnt,min(dfs(k+1),dfs(k-1))+1);    //奇数则+1或-1 
	mp[k]=cnt;                   //记忆化搜索 
	return mp[k];            
}
int main(void){
	while(cin>>x>>y){
		mp.clear();
		res=dfs(y);
		cout<<res<<endl;
	}
	return 0;
}
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <functional>
#include <utility>
#include <tuple>
#include <numeric>
#include <queue>
#include <cstring>
#include <sstream>
#include <iomanip>
#include <regex>
#include <stack>
#include <limits>
#include <climits>

using namespace std;

map<long long, long long> f;

long long calc(long long y, long long x) {
	if (f.count(y) > 0) return f[y];
	if (y <= x) return x - y;
	long long res = y - x;
	if (y % 2 == 1) {
		res = min(res, 2+calc((y + 1) / 2, x));
		res = min(res, 2 + calc((y - 1) / 2, x));
	} else {
		res = min(res, 1 + calc(y / 2, x));
	}
	return f[y] = res;
}

int main() {
	ios_base::sync_with_stdio(false);
	long long x, y;
	cin >> x >> y;
	if (x >= y) {
		cout << x - y;
	} else {
		cout << calc(y, x);
	}
	cout << endl;
	return 0;
}
