#include <bits/stdc++.h>
#define REP(i, nn ) for(int i = 0 ; i < (int) nn; i++)
#define REPS(i, ss, nn ) for(int i = ss ; i < (int) nn; i++)
#define REV(i, ss, nn ) for(int i = ss ; i >= nn; i--)
#define deb(x) std::cout << #x << " " << x << endl;
#define debl(x) std::cout << #x << " " << x << " ";
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
namespace std{
    template<class Fun>
    class y_combinator_result{
        Fun fun_;
        public:
            template<class T>
            explicit y_combinator_result(T &&fun) : fun_(std::forward<T>(fun)){}
            template<class ...Args>
            decltype(auto) operator()(Args&&...args){
                return fun_(std::ref(*this), std::forward<Args>(args)...);
            }
    };
    template<class Fun>
    decltype(auto) y_combinator(Fun && fun){
        return y_combinator_result<std::decay_t<Fun>>(std::forward<Fun>(fun));
    }
};
template<typename T>
bool u_max(T& a, T b){
    if( a < b){
        a = b;
        return true;
    }
    return false;
}
template<typename T>
bool u_min(T& a, T b){
    if( a > b){
        a = b;
        return true;
    }
    return false;
}
// struct edge{
//     int to, from;
//     ll cost;
//     edge(){ edge(0,0);}
//     edge(int to_, ll cost_){ edge(0, -1, 0);}
//     edge(int to_, int from_, ll cost_) : to(to_), from(from_), cost(cost_){}
// };

template<typename... T>
void read(T& ... a){
    ((cin >> a),...);
}

void solve(){
    ll x, y;
    read(x, y);
    ll ans = abs(y - x);
    ll base = 2 * x;
    int n_pow = 1;

    auto count_bit = [&](ll d, int bit_num){
        ll ret = 0;
        int count = 0;
        for(int i = 0 ; i < bit_num; i++){
            // deb(d) deb(last)
            if( d % 2 == 1){
                count++;
            }else{
                if(count >= 2){
                    ret++;
                    d += 1;
                    count = 1;
                }else{
                    ret += count;
                    count = 0;
                }
            }
            d /= 2;
        }
        // debl(ret) debl(count) deb(d)
        if(count <= 2){
            return ret + count + d;
        }else{
            //count -> 2
            // d -> d -1
            return ret + d + 2;
        }
    };
    // 11100010 ==> 1000010 - 10000

    while(abs(base - y) < 4 * abs(x - y) ){
        ll diff = abs(y - base);
        // debl(base) deb(diff) 
        ll op_num = count_bit(diff, n_pow);
        // deb(op_num)
        u_min(ans, n_pow + op_num);
        base *= 2;
        n_pow++;
    }
    cout << ans << endl;
}

int main()
{
    //making data IO Fast
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    /****************************/
    solve();
    return 0;
}


#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  //f
  long long x, y;
  cin >> x >> y;
  map<long long, long long> memo;
  auto rec = [&] (auto&& self, long long cur) -> long long {
    if (memo.count(cur)) return memo[cur];
    if (cur <= x) return x - cur;
    if (cur % 2 == 0) {
      return memo[cur] = min(cur - x, self(self, cur / 2) + 1);
    } else {
      return memo[cur] = min({cur - x, self(self, (cur + 1) / 2) + 2, self(self, (cur - 1) / 2) + 2});
    }
  };
  cout << rec(rec, y) << endl;
  return 0;
}