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

LL X, Y;
map<LL, LL> memo;
LL solve(LL y) {
    if(memo.count(y)) return memo[y];
    if(y == 1) return memo[y] = llabs(X-y);
    if(y % 2 == 1) return memo[y] = min(llabs(X-y), min(solve((y+1)/2) + 2, solve((y-1)/2) + 2));
    if(y % 2 == 0) return memo[y] = min(llabs(X-y), solve(y/2) + 1);
    return memo[y];
}

int main() {
    memo.clear();
    cin >> X >> Y;
    if(Y <= X){
        cout << X - Y << endl;
        return 0;
    }
    cout << solve(Y) << "\n";
}

//#include <atcoder/all>
//using namespace atcoder;
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(int i=0; i<n; i++)
#define REPR(i, n) for(int i=n-1; i>=0; i--)
#define FOR(i, m, n) for(int i=m; i<n; i++)
#define ALL(v) v.begin(), v.end()
#define bit(n) (1LL<<(n))
#define FIX(d) fixed << setprecision(d)
using P = pair<int, int>;
using LP = pair<ll, ll>;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 1e9;
const ll LINF = (1LL<<60);

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll X,Y; cin >> X >> Y;
  ll ans = LINF;
  map<ll, ll> memo;
  priority_queue<LP, vector<LP>, greater<LP>> que;
  que.emplace(0, Y);
  while(!que.empty()){
    auto [v, x] = que.top();
    que.pop();

    if(v>=ans) continue;
    chmin(ans, v+abs(X-x));

    int r = (x&1);
    ll nv = v+r+1;
    int d = 2;
    if(nv<ans && (!memo.count(x/d) || nv<memo[x/d])){
      que.emplace(nv, x/d);
      memo[x/d] = nv;
    }
    nv = v+(d-r)+1;
    if(nv<ans && (!memo.count(x/d+1) || nv<memo[x/d+1])){
      que.emplace(nv, x/d+1);
      memo[x/d+1] = nv;
    }
  }
  cout << ans << endl;
  return 0;
}
