#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

using namespace std;
using namespace __gnu_pbds;

#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pt;
typedef pair<ll,ll> pll;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
//#define ordered_set tree<pair<int, int>,null_type,less<pair<int, int>>,rb_tree_tag,tree_order_statistics_node_update>

#define vint vector<int>
#define vll vector<long long>
#define endl '\n'
#define fi first
#define se second
#define pb push_back
#define F(i,n) for(int i = 0;i<n;i++)
#define Fr(i,l,r) for(int i = l;i <= r;i++)
#define rF(i,n) for(int i = n-1;i>=0;i--)
#define Max 1000001
#define intinf 2147483647
#define longlonginf 9223372036854775807
#define MOD 998244353
#define MOD2 1000000007
#define fastio ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define all(arr) arr.begin(),arr.end()
//#define sort(vec) sort(vec.begin(),vec.end())
//#define reverse(vec) reverse(vec.begin(),vec.end())

ll Lpow(ll a,ll b)
{
    ll ans = 1;
    while(b > 0)
    {
        if(b%2)
            ans = (ans*a);
        a = (a*a);
        b = b/2;
    }
    return ans;
}

ll Lpow(ll a,ll b,ll M)
{
	ll ans = 1;
	while(b > 0)
	{
		if(b%2)
			ans = (ans*a)%M;
		a = (a*a)%M;
		b = b/2;
	}
	return ans;
}

ll x,y;
ll ans;
map<ll,ll> mape;

void sch(ll y,ll turns)
{
    ans = min(ans,abs(y - x) + turns);
    if(mape[y] <= turns && mape[y] != 0)
        return;
    else
    {
        mape[y] = turns;
        if(y%2)
        {
            sch(y + 1,turns + 1);
            sch(y - 1,turns + 1);
        }
        else
            sch(y/2,turns + 1);
    }
}


int main()
{
    fastio;
	
    ans = longlonginf;
    cin >> x >> y;

    sch(y,0);

    cout << ans << endl;

	return 0;
}
#include <bits/stdc++.h>
using namespace std;

typedef long long int ll;
#define int ll
#define fast(); ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define tests() int t; cin>>t; while(t--)
#define endl '\n'
#define sz(x) ll((x).size())
#define F first
#define S second
#define mp make_pair
#define vi vector <ll>
#define pii pair<ll, ll>
#define pdi pair<double, ll>
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define all(x) x.begin(),x.end()
#define f(i,n) for(ll i=0;i<n;i++)

#define shout()  {cout << "I'm Here...!!!" << endl;}
#define dbg(x) { cout<< #x << ": " << (x) << endl; }
#define dbg2(x,y) { cout<< #x << ": " << (x) << " , " << #y << ": " << (y) << endl; }
#define dbgv(x) { cout<< #x << ": "; for(auto i : x) cout << i << ' '; cout << '\n'; }

int inf = 1e18 + 100;
int mod = 1e9 + 7;
double pi = 3.1415926;

int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a); }
int fpow(int a, int b, int _mod = mod) { if (b == 0)return 1; int t = (fpow(a, b / 2, _mod)); if (b % 2 == 0)return (t * t) % _mod; else return ((a) * (t * t)) % _mod; }

vi parent;
void make_set(int n) { parent.resize(n); f(i, n) parent[i] = i; }
int find_set(int v) { if (v == parent[v]) return v; return parent[v] = find_set(parent[v]); }
bool union_sets(int a, int b) { a = find_set(a); b = find_set(b); parent[b] = a; return a != b; }

signed main()
{
	int x, y, res = 0;
	cin >> x >> y;
	if (x >= y) {
		cout << x - y << endl;
		return 0;
	}
	res = y - x;
	int t = 1, k = 0, s = 1;
	while (x*s < 2*y) {
		k++;
		s *= 2;
		t = (k+1)*s;
		int d = abs(y - x*s);
		if (d > x * s) continue;//res = min(res, k + (d - t) + k + 1);
		else {
			int q = 0;
			int ss = s/2;
			while (d > 0) {
				q += d / s, d %= s;
				if (d > ss) d = min(ss * 2 - d, d - ss), q++;
				ss /= 2;
			}
			res = min(res, q + k);
		}
	}
	cout << res << endl;
}