#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <cstring>
#include <cstdlib>
#include <cmath>
using namespace std;
using ll = long long;

map<ll, ll> mp;

ll f(ll x, ll y) {
    auto it = mp.find(y);
    if (it != mp.end()) return it->second;

    if (x >= y) return x - y;

    ll r = y - x;
    if (y % 2) {
        r = min(r, f(x, (y - 1) / 2) + 2);
        r = min(r, f(x, (y + 1) / 2) + 2);
    } else {
        r = min(r, f(x, y / 2) + 1);
    }

    return mp[y] = r;
}

int main() {
    ll x, y;
    cin >> x >> y;

    cout << f(x, y) << endl;

    return 0;
}
//Think simple yet elegant.
#include <bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll  long long
#define all(v) v.begin(),v.end()
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define pi pair<int,int>
#define REP(i,n) for(int i=0;i<n;i++)
const int N = 2e5+2;
const ll mod = 1e9+7;


map<ll,ll> dp;
map<ll,bool> seen;
ll x,y;

ll solve(ll cur){
	if(seen[cur])
		return dp[cur];

	if(cur<=x){
		seen[cur]=true;
		dp[cur]=abs(cur-x);
		return dp[cur];
	}

	ll ans = cur-x;
	if(cur%2==0)
		ans = min(ans,solve(cur/2)+1);	
	else
		ans = min({ans,solve(cur+1)+1,solve(cur-1)+1});

	seen[cur]=true;
	return dp[cur]=ans;

}
 
int main(){
	fast;
	int tt;
	tt=1;
	while(tt--){
		cin >> x >> y;
		cout<<solve(y)<<"\n";
	}
	
	
}






