#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pi pair<int,int>
#define f first
#define s second
#define ld long double
const int nax=205;
map<int,int> vis,dp;
int x,y;
int find(int v)
{
    if(vis[v])
    return dp[v];
    vis[v]=1;
    dp[v]=1e18;
    int& res=dp[v];
    res=min(res,abs(v-x));
    if(v==1)
    return res;
    if(v%2==0)
    res=min(res,1+find(v/2));
    else
    res=min(res,1+min(find(v+1),find(v-1)));
    return res;
}
void solve()
{
    cin>>x>>y;
    cout<<find(y);
}
signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr);
    int t=1;
    //cin>>t;
    while(t--)
    solve();
    return 0;
}
#include<bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
#define rep(i,n) for(int i=0; i<(n); i++)

int main(){
  LL X,Y; cin>>X>>Y;
  if(X>Y){ cout<<(X-Y)<<endl; return 0; }
  LL L=0, LV=Y, R=1, RV=Y+1;
  LL ans=Y-X;
  rep(i,70){
    ans=min(ans,abs(LV-X)+L);
    ans=min(ans,abs(RV-X)+R);
    LL newL,newR;
    if(LV%2==0){
      LV/=2; RV=LV+1;
      newL=min(L+1,R+2); newR=min(L+2,R+2);
    }
    else {
      RV/=2; LV=RV-1;
      newL=min(L+2,R+2); newR=min(L+2,R+1);
    }
    L=newL; R=newR;
  }
  cout<<ans<<endl;
  return 0;
}
