#include <iostream>
#include <map>
using namespace std;
typedef long long ll;

const ll INF = 1000000000000000000;

ll dfs(ll z, int j, ll y, map<ll, ll> &mp){
    if(j == 0){
        return mp[z] = abs(z - y);
    }
    if(mp.count(z)) return mp[z];
    ll res = INF;
    if(((z + 1) << j) <= y){
        res = min(res, dfs((z + 1) * 2, j - 1, y, mp) + 2);
    }
    else if((z << j) <= y){
        res = min(res, dfs((z + 1) * 2, j - 1, y, mp) + 2);
        res = min(res, dfs(z * 2, j - 1, y, mp) + 1);
    }
    if(((z - 1) << j) >= y){
        res = min(res, dfs((z - 1) * 2, j - 1, y, mp) + 2);
    }
    else if((z << j) >= y){
        res = min(res, dfs((z - 1) * 2, j - 1, y, mp) + 2);
        res = min(res, dfs(z * 2, j - 1, y, mp) + 1);
    }
    return mp[z] = res;
}

int main()
{
    ll x, y;
    cin >> x >> y;
    ll ans = abs(y - x);
    map<ll, ll> mp;
    for(int i = 0; i <= 60; i++){
        ll l = y, r = y;
        for(int j = 0; j < i; j++){
            l = l / 2;
            r = (r + 1) / 2;
        }
        if(l == 0) break;
        ll z = x;
        ll s = 0;
        if(z < l){
            s += l - z;
            z = l;
        }
        if(z > r){
            s += z - r;
            z = r;
        }
        ans = min(ans, dfs(z, i, y, mp) + s);
    }
    cout << ans << endl;
}

#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#include <algorithm>
#include <bitset>
#include <complex>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#include <cassert>
#include <functional>

using ll = long long;
using namespace std;

template<typename A, typename B>
bool chmin(A &a, const B b) {
  if (a <= b) return false;
  a = b;
  return true;
}

template<typename A, typename B>
bool chmax(A &a, const B b) {
  if (a >= b) return false;
  a = b;
  return true;
}

#ifndef LOCAL
#define debug(...) ;
#else
#define debug(...) cerr << __LINE__ << " : " << #__VA_ARGS__ << " = " << _tostr(__VA_ARGS__) << endl;

template<typename T>
ostream &operator<<(ostream &out, const vector<T> &v);

template<typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template<typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}

void _tostr_rec(ostringstream &oss) {
  oss << "\b\b \b";
}

template<typename Head, typename... Tail>
void _tostr_rec(ostringstream &oss, Head &&head, Tail &&...tail) {
  oss << head << ", ";
  _tostr_rec(oss, forward<Tail>(tail)...);
}

template<typename... T>
string _tostr(T &&...args) {
  ostringstream oss;
  int size = sizeof...(args);
  if (size > 1) oss << "{";
  _tostr_rec(oss, forward<T>(args)...);
  if (size > 1) oss << "}";
  return oss.str();
}
#endif

constexpr int mod = 1'000'000'007; //1e9+7(prime number)
constexpr int INF = 1'000'000'000; //1e9
constexpr ll LLINF = 2'000'000'000'000'000'000LL; //2e18
constexpr int SIZE = 200010;


int main() {
  ll X, Y;
  ll ans = LLINF;

  cin >> X >> Y;

  set<ll> visited;
  queue<pair<ll, int>> que;

  que.push({Y, 0});

  while (que.size()) {
    auto p = que.front();
    que.pop();

    if (visited.count(p.first)) continue;
    visited.insert(p.first);

    chmin(ans, abs(p.first - X) + p.second);

    if (p.first % 2) {
      que.push({p.first + 1, p.second + 1});
      que.push({p.first - 1, p.second + 1});
    } else {
      que.push({p.first / 2, p.second + 1});
    }
  }


  cout << ans << endl;

  return 0;
}