#include <bits/stdc++.h>
#define fi first
#define se second
#define ins insert
#define pb push_back
#define sz(x) ((int)x.size())
#define all(x) x.begin(), x.end()
#define fk(x, a, b) for (int x = (a); x < (b); ++x)
#define fb(x, a, b) for (int x = (a); x <= (b); ++x)
#define fan(x, a, b) for (int x = (a); x >= (b); --x)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef unsigned long long ull;
map<ll, ll> is;
ll ff(ll x, ll y) {
	if (is[y]) return is[y];
	if (x >= y) return is[y] = x - y;
	if (y % 2) {
		return is[y] = min(y - x, min(ff(x, y - 1) + 1, ff(x, y + 1) + 1));
	}
	else {
		return is[y] = min(y - x, ff(x, y / 2) + 1);
	}
}
int main() {
	ios::sync_with_stdio(0);	
	cin.tie(0);
	cout.tie(0);
	ll x, y;
	cin >> x >> y;
	cout << ff(x, y) << endl;
    return 0;
}
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

int main(){
    long X, Y;
    cin >> X >> Y;
    unordered_map<long, long> dp;
    function<long(long)> solve = [&](long y){
        if(dp[y]) return dp[y];
        if(y == 1) return dp[y] = abs(X - y);
        if(y & 1) return dp[y] = min({abs(X - y), solve((y + 1) / 2) + 2, solve((y - 1) / 2) + 2});
        else return dp[y] = min(abs(X - y), solve(y / 2) + 1);
    };
    cout << solve(Y) << endl;
    return 0;
}