#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define ll long long
#define f first
#define s second
#define pii pair<int,int>


const int N =3e5+5;
const int MOD = 1e9+7;

ll qpow(ll a, ll b, ll m)
{
    ll  ans=1;
	while(b)
	{
		if(b&1)
			ans=(ans*a)%m;
		b/=2;
		a=(a*a)%m;
	}
	return ans;
}

//vector<int>adj[200005];
//vector<int>a,val;
//vector<bool>vis;
int a[200005];
int val[200005];
bool vis[200005];
vector<int>adj[200005];
ll ans = -1e18;

void dfs(int v, int par){
    vis[v] = true;
    for(int u:adj[v]){
        if(u!=par){
            ans = max(ans, (ll)a[u]-val[v]);
            val[u] = min(val[v], a[u]);
            if(!vis[u])
              dfs(u, v);
        }
    }
}

ll x,y;
map<ll,ll>m;

ll func(ll v){
    if(v<=x){
        return m[v] = x-v;
    }
    if(m[v]) return m[v];
    ll val = v-x;
    if(v%2){
        val = min(val, func(v-1)+1);
        val = min(val, func(v+1)+1);
    }
    else{
        val = min(val, func(v/2)+1);
    }
    return m[v] = val;
}

int main()
{
	IOS;
	
	int t=1; //cin>>t;
	while(t--){
	    cin>>x>>y;
	    cout<<func(y);
	    
	   
	}
}	
	
	
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll x,y;
map<ll,ll>f;
ll dfs(ll u)
{
	if(!u)		return x;
	if(f[u])	return f[u];
	ll	&ans=f[u];
	ans=abs(x-u);
	if(u%2==0)	ans=min(ans,1+dfs(u/2));
	else		ans=min(ans,min(1+dfs(u-1),1+dfs(u+1)));
	return ans;
}
int main()
{
	cin>>x>>y;
	printf("%lld\n",dfs(y));			
	return 0;
}