#include <bits/stdc++.h>

using namespace std;

long long rec(long long cur, long long tar) {
  static unordered_map<long long, long long> dp;
  if (dp.count(cur)) return dp[cur];
  if (cur <= tar) return dp[cur] = tar - cur;
  
  if (cur & 1) {
    return dp[cur] = min({cur - tar, rec(cur >> 1, tar) + 2, rec((cur + 1) >> 1, tar) + 2});
  } else {
    return dp[cur] = min(cur - tar, rec(cur >> 1, tar) + 1);
  }
}

int main() {
  long long X, Y;
  cin >> X >> Y;
  
  cout << rec(Y, X) << endl;
  
  return 0;
}
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

typedef long long ll;

int main() {
    ll X, Y;
    cin >> X >> Y;
    if (X >= Y) {
        cout << X - Y << "\n";
        return 0;
    }
    map<ll, int> mp;
    queue<ll> q;
    q.push(Y);
    mp[Y] = 0;
    ll ans = 1e18;
    while(!q.empty()) {
        ll p = q.front();
        q.pop();
        ans = min(ans, mp[p] + abs(X - p));
        if (p % 2) {
            if (mp.find(p + 1) == mp.end()) {
                q.push(p + 1);
                mp[p + 1] = mp[p] + 1;
            }
            if (mp.find(p - 1) == mp.end()) {
                q.push(p - 1);
                mp[p - 1] = mp[p] + 1;
            }
        } else {
            if (mp.find(p / 2) == mp.end()) {
                q.push(p / 2);
                mp[p / 2] = mp[p] + 1;
            }
        }
    }
    cout << ans << "\n";
}