                #include<bits/stdc++.h>
                #define ll long long
                #define f first
                #define s second
                #define mod         1000000007 
#define pb          push_back
                using namespace std;
                ll ans,n,m;
                map<ll,ll> vis,dp;
                ll recur(ll x)
                {
                    if(vis[x]) return dp[x];
                    vis[x]=1;
                    dp[x]=abs(x-n);
                    if(x==n) {return dp[x];}

                    if(x%2==0) dp[x]=min(dp[x],1+recur(x/2));
                    else
                    {
                        dp[x]=min({dp[x],1+recur(x-1),1+recur(x+1)});
                    }
                    return dp[x];
                }
                void solve()
                {       
                    
                    cin>>n>>m;
                    ans=abs(n-m);
                    //cout<<ans<<" ";
                    cout<<recur(m);





                }
                int main()  
                {   
                    ll t=1;
                   // cin>>t;
                    while(t--)
                    solve();
                }            

#include <bits/stdc++.h>
using namespace std;
  #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #define int long long
  #define endl "\n"
  #define all(v) v.begin(),v.end()
  #define double long double
  #define trace1(x)                cerr<<#x<<": "<<x<<endl
  #define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
  #define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
  #define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
  #define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<< ": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
  #define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
  #define cases int testcases;cin>>testcases; while(testcases--)
  const int N = 200005;
  #define rep(i, x, y)   for (__typeof(x) i = x; i <= y; i ++)
  #define repi(i, x, y)  for (__typeof(x) i = x; i >= y; i --)


int x;
  
map<int,int> dp;


int rec(int curr)
{
  if(curr <= x)return x-curr;
  if(dp.find(curr) != dp.end())return dp[curr];
  int ans = curr-x;

  if(curr%2 == 0)
  {
    if(curr/2 > x)ans = min(ans,1 + rec(curr/2));
    else ans = min(ans, 1 + x - curr/2);
  }
  else if(curr + 1 == x or curr - 1 == x)return 1;
  else
  {
    ans = min({ans,2 + rec((curr+1)/2),2 + rec((curr-1)/2)});
  }
  return dp[curr] = ans;
}
int32_t main()
{


    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    IOS


    int y;
    cin >> x >> y;



    cout << rec(y);



    return 0;
}
