#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define ALL(a) (a).begin(), (a).end()

#define min_e(v) *min_element(ALL(v))
#define max_e(v) *max_element(ALL(v))

#define acm accumulate
#define SUM(v) accumulate(ALL(v), 0l)
#define SORT(v) sort(ALL(v))
#define P 1000000007
long powP (long a, long b) {
  if (b == 1) return a;
  else if (b == 0) return 1;
  else if (b < 0) return powP(a, P - 1 + b);
  else {
    long b2 = powP(a, b/2);
    b2*=b2;
    b2%=P;
    return (b2 * powP(a, b%2)) % P;
  }
}

template <typename T>
using vec = vector<T>;

template <typename T>
using vvec = vector<vector<T>>;

#define INF INT_MAX

#define x first
#define y second

long sa (long b, int n) {
  long c = b % (long)pow(2, n);
  b /= (long)pow(2, n);
  while (c != 0) {
    while (c%2==0) c/=2;
    if (c%4==3) {
      c++;
      b++;
    } else {
      c--;
      b++;
    }
  }
  return b;
}

int main() {
  long x, y;
  cin>>x>>y;
  long ans = LONG_MAX;
  for (int n = 0; pow(2, n)*x<LONG_MAX; n++) {
    long b = abs(y-x*(long)pow(2, n));
    ans = min(ans, sa(b, n)+n);
  }
  cout<<ans;
}

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define bit(n,k) ((n>>k)&1)
using namespace std;
typedef long long ll;

ll x,y;
unordered_map<ll,ll> mp;
ll Dfs(ll n){
    if(n <= x) return x - n;
    if(n % 2 == 0) return mp[n] = min(n - x, Dfs(n / 2) + 1);
    if(mp.count(n)) return mp[n];
    return mp[n] = min(Dfs(n + 1), Dfs(n - 1)) + 1;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);

    cin >> x >> y;
    cout << Dfs(y) << '\n';
}