#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib> 
#include <ctime>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define x first
#define y second
#define all(v) v.begin(), v.end()
#define compress(v) (sort(all(v)), v.erase(unique(all(v)), v.end()))
typedef long long ll;
typedef pair<ll, ll> p;
int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	ll X, Y; cin >> X >> Y;
	unordered_set<ll> visited;
	queue<p> q;
	q.push({ Y,0 });
	ll ans = (ll)1e18; visited.insert(Y);
	while (!q.empty()) {
		p cur = q.front(); q.pop();
		ll y = cur.x, cnt = cur.y;
		if (cnt >= ans) continue;
		if (y == X) {
			ans = min(ans, cnt); continue;
		}
		ans = min(ans, cnt + abs(y - X));
		if (y < X) continue;
		if (y % 2 == 0) {
			if (visited.find(y / 2) == visited.end()) {
				q.push({ y / 2,cnt + 1 });
				visited.insert(y / 2);
			}
		}
		else {
			if (visited.find(y + 1) == visited.end()) {
				q.push({ y + 1,cnt + 1 });
				visited.insert(y + 1);
			}
			if (visited.find(y - 1) == visited.end()) {
				q.push({ y - 1,cnt + 1 });
				visited.insert(y - 1);
			}
		}
	}
	cout << ans;
}
#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;

#define rep(i,x,y) for(ll i=(x);i<(y);i++)
#define rrep(i,x,y) for(ll i=(ll)(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
#define itrout(x) for(int i=0;i<x.size();i++) {cout << x[i] << (i==x.size()-1 ? "\n" : " ");}
#ifdef LOCAL
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#define debugbit(x, n) cerr << #x << " = " << bitset<n>(x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#define itrdebug(x) cerr << #x << " "; for (auto & el : (x)) {cerr << (el) << " ";} cerr << endl
#define dassert(...) assert(__VA_ARGS__)
#else
#define debug(x)
#define debugbit(x, n)
#define itrdebug(x)
#define dassert(...)
#endif
//#define int long long
//using mint = atcoder::modint;

typedef long long ll;
const ll MOD = 1e9 + 7;
const long double EPS = 1e-8;


signed main(){
    ll X, Y;
    cin >> X >> Y;
    if (Y <= X) {
        cout << X - Y << endl;
        return 0;
    }
    unordered_map<ll, ll> memo;
    auto dfs = [&](auto&& self, ll current) -> ll {
        if (memo.find(current) != memo.end()) return memo[current];
        ll minCost = abs(current - X);
        if (X < current) {
            for (const int add : {1, -1}) {
                ll costDiff = 0, next = current;
                while (next % 2 != 0) {
                    next += add;
                    costDiff++;
                }
                next /= 2;
                costDiff++;
                assert(next < current);
                minCost = min(minCost, self(self, next) + costDiff);
            }
        }
        return memo[current] = minCost;
    };
    cout << dfs(dfs, Y) << endl;
}
