#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define reps(i,n) for (int i = 1; i <= (n); ++i)
#define rrep(i,n) for (int i = (n) - 1; i >= 0; --i)
#define rreps(i,n) for (int i = (n); i > 0; --i)
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define PB push_back
#define MP make_pair
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
using namespace std;
using ll = long long;
using P = pair<int,ll>;

ll x, y;

int main() {
  cin >> x >> y;
  
  if (x >= y) {
    cout << x - y << endl;
    return 0;
  }

  ll ans = 2e18;
  map<ll, int> d;
  priority_queue<P, vector<P>, greater<P>> que;
  d[y] = 0;
  que.push(MP(d[y], y));
  while (que.size()) {
    P p = que.top(); que.pop();
    ll yy = p.second;
    // printf("yy = %lld\n", yy);
    if (p.first > d[yy]) continue;
    ans = min(ans, d[yy] + abs(yy - x));
    if (yy <= x) continue;
    if (yy % 2 == 0) {
      if (d[yy / 2] != 0 && d[yy / 2] <= d[yy] + 1) continue;
      d[yy / 2] = d[yy] + 1;
      que.push(MP(d[yy / 2], yy / 2));
    } else {
      if (d[yy / 2] == 0 || d[yy / 2] > d[yy] + 2) {
        d[yy / 2] = d[yy] + 2;
        que.push(MP(d[yy / 2], yy / 2));
      }
      if (d[yy / 2 + 1] == 0 || d[yy / 2 + 1] > d[yy] + 2) {
        d[yy / 2 + 1] = d[yy] + 2;
        que.push(MP(d[yy / 2 + 1], yy / 2 + 1));
      }
    }
  }

  cout << ans << endl;
  return 0;
}

#include<bits/stdc++.h>
using namespace std;
long long x,y;
map<long long,long long>dp;
long long rec(long long now){
  if(x>=now)return x-now;
  if(dp[now])return dp[now];
  long long res=now-x;
  if(res>rec(now/2)+now%2+1)res=rec(now/2)+now%2+1;
  if(res>rec((now+1)/2)+now%2+1)res=rec((now+1)/2)+now%2+1;
  return dp[now]=res;
}
int main(){
  cin>>x>>y;
  cout<<rec(y)<<endl;
  return 0;
}