#include<bits/stdc++.h>
#define ll long long int
#define ld long  double
using namespace std;
#define fio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define endl "\n"
#define maxpq priority_queue<ll>
#define minpq priority_queue<ll, vector<ll>, greater<ll> >
#define vi vector<ll>
#define pii pair<ll, ll>
#define vii vector<pii>
#define for0(i, n) for (int i = 0; i < n; i++)
#define for1(i, n) for (int i = 1; i <= n; i++)
#define loop(i,a,b) for (int i = a; i < b; i++)
#define bloop(i,a,b) for (int i = a ; i>=b;i--)

#define INT_MAXI 9000000000000000000
#define INT_MINI -9000000000000000000

ll max(ll a, ll b) {if (a > b) return a; else return b;}
ll min(ll a, ll b) {if (a < b) return a; else return b;}

const int dx[4] = { -1, 1, 0, 0};
const int dy[4] = {0, 0, -1, 1};
int XX[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
int YY[] = { -1, 0, 1, -1, 1, -1, 0, 1 };

ll n,m;
ll arr[200005];
ll arr2[200005];
bool visited[200005];
ll ans=0,maxi=0;
vector<ll>vec[200005];
vi vec2,ans2;

/*void dfs(ll node,ll mini)
{
	vec2.pb(node);
	ans=max(ans,arr[node]-mini);
	
	
	for(auto itr:vec[node])
	{
		if(!visited[itr])
		{
			visited[itr]=1;
			maxi=max(maxi,arr[itr]);
			dfs(itr,min(mini,arr[itr]));
			
			
		}
		else
		{
			ans=max(ans,arr2[itr]-mini);
			
			
		}
		
		
		
		
	}
	
	
	
	
	
}*/

map<ll,ll>mpp;

ll func(ll x,ll y)
{
	
	if(x>=y)
	return x-y;
	if(mpp.count(y))
	return mpp[y];
	ll count=INT_MAXI;
	count=abs(x-y);
	if(y%2==0)
	{
		count= min(count,1+func(x,y/2));
	}
	else
	{
		count=min(count,min(func(x,y/2),func(x,y/2+1))+2);
	}
	return mpp[y]= count;
	
	
}

  
int main()
{
    
	fio;
    ll t,i,j,u,v,x,k,p,c,y,a,b;
    cin>>x>>y;
    ll ans=func(x,y);
    cout<<ans<<endl;
    
  
}
#include <bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
/*---------------------DEBUGGING--------------------------------------------*/
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
/*-------------------------------------------------------------------------------------*/
#define pb push_back
#define ll long long
#define pii pair<int,int>
#define pcc pair<char,char>
#define F first
#define S second
#define int long long
#define pi 3.141592653589793238462643383279502
#define M  1000000007
#define rep(i,a,n) for(int i=a;i<n;i++)
#define INF 10000000000005
#define N 200005
#define vi vector<int>
#define all(v) v.begin(),v.end()
#define endl "\n"
unordered_map<int,int>dp;
unordered_map<int,int>vis;
int x,y;
int calc(int val)
{
    if(val<=x)return (x-val);
    if(vis.count(val))return dp[val];
    vis[val]=1;
    int ans=abs(val-x);
    if(val & 1)
    {
        ans=min(ans,2 + calc((val+1)/2));
        ans=min(ans,2 + calc((val-1)/2));
    }
    else
    {
        ans=min(ans,1 + calc(val/2));
    }
    return dp[val]=ans;

}
void solve()
{

    cin>>x>>y;
    if(x>=y)
    {
        cout<<(x-y)<<endl;
        return;
    }
    cout<<calc(y)<<endl;

}
signed main()
{
   ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
   int tests;
   //cin>>tests;
   tests=1;
   for(int i=0;i<tests;i++)
   {
       solve();
   }
}
