#include <bits/stdc++.h>
using namespace std;
typedef int64_t ll;
ll x, y;
map<ll, ll> vis, cache;
ll solve(ll val);
int main() {
	//freopen("input.txt", "r", stdin);
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> x >> y;
	cout << solve(y) << endl;
	return 0;
}
ll solve(ll val) {
	if (vis[val]) return cache[val];
	vis[val] = 1;
	cache[val] = 1e18;
	ll &ans = cache[val];
	ans = min(ans, abs(val - x));
	if (val == 1) return ans;
	if (!(val & 1)) ans = min(ans, 1 + solve(val / 2));
	else ans = min(ans, 1 + min(solve(val + 1), solve(val - 1)));
	return ans;
}
#include <bits/stdc++.h>
using namespace std;
#define int long long
int32_t main(){
    int x,y;
    cin>>x>>y;
    if(x>=y){
        cout<<x-y;
        return 0;
    }
    int ans=y-x;
    queue<pair<int,int>>q;
    q.push({0,y});
    set<int>s;
    while(!q.empty()){
        pair<int,int>f=q.front();
        q.pop();
        if(s.find(f.second)!=s.end())
            continue;
        s.insert(f.second);
        ans=min(ans,f.first+abs(x-f.second));
        if(f.second<x)
            continue;
        if(f.second&1){
            q.push({f.first+1,f.second-1});
            q.push({f.first+1,f.second+1});
        }
        else
            q.push({f.first+1,f.second>>1});
    }
    cout<<ans;
    return 0;
}