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

// Consecutive additon/subtraction is bad
// if x < y /4 , then its optimal to

long long int do_brute(long long int x, long long int y){
  if(x == y)
    return 0;
  if(y%2 == 0){
    if(y >= 2*x)
      return 1 + do_brute(x,y/2);
    else
      return min(y-x,1+x-y/2);
  }
  else
    return 1 + min(do_brute(x,y+1),do_brute(x,y-1));
}

int main(){
  long long int x,y,oper = 0;
  cin>>x>>y;
  if(x >= y)
    cout<<x-y;
  else{
    while(4*x < y){
      if(y%2 == 0)
        y/=2;
      else if(y%4 == 1)
        --y;
      else
        ++y;

      ++oper;
    }

    oper += do_brute(x,y);
    cout<<oper;
  }
  return 0;
}

#include<bits/stdc++.h>
#define ll long long
#define rep(i, m, n) for (int i = m; i <= n; i++)
#define per(i, m, n) for (int i = m; i >= n; i--)
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define INF 0x3f3f3f3f
using namespace std;

ll x, y;
unordered_map<ll, ll> M;

ll solve(ll num) {
    if (M.count(num)) return M[num];
    if (num == 1) return abs(x - num);
    if (num & 1) {
        return M[num] = min(min(abs(num - x), solve((num + 1) / 2) + 2), solve((num - 1) / 2) + 2);
    }
    return M[num] = min(abs(num - x), solve(num / 2) + 1);
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cin >> x >> y;
    cout << solve(y) << "\n";
    return 0;
}
