#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <climits>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <cassert>
#include <stack>
#include <numeric>

typedef long long ll;
typedef std::pair<int, int> Pii;
typedef std::pair<long long, long long> Pll;
typedef std::pair<double, double> Pdd;

#define rip(i, n, _s) for (int i = (_s);i < (int)( n ); i++)
#define all(_l) _l.begin(), _l.end()
#define rall(_l) _l.rbegin(), _l.rend()
#define MM << " " <<

template<typename T>
using MaxHeap = std::priority_queue<T>;
template<typename T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<typename T>
inline bool chmax(T &_l, const T b) {
    if (_l < b) {
        _l = b;
        return true;
    }
    return false;
}
template<typename T>
inline bool chmin(T &_l, const T b) {
    if (_l > b) {
        _l = b;
        return true;
    }
    return false;
}

# ifdef LOCAL_DEBUG
template<typename T>
void vdeb(const std::vector<T> &bb) {
    for (unsigned int i = 0;i < bb.size();i++) {
        if (i == bb.size() - 1) std::cout << bb[i];
        else std::cout << bb[i] << ' ';
    }
    std::cout << '\n';
}
template<typename T>
void vdeb(const std::vector<std::vector<T>> &bb) {
    for (unsigned int i = 0;i < bb.size();i++) {
        std::cout << i << ' ';
        vdeb(bb[i]);
    }
    std::cout << '\n';
}
# endif

using namespace std;

map<ll, ll> mp;

ll rec(const ll x, const ll y) {
    ll ret = abs(x-y);
    if(y == 1) return ret;
    if(mp.count(y)) return mp[y];
    if(y&1) {
        chmin(ret, min(rec(x, (y+1)>>1), rec(x, (y-1)>>1))+2);
    }
    else {
        chmin(ret, rec(x, y>>1)+1);
    }
    mp[y] = ret;
    return ret;
}

int main() {
    ll x, y; cin >> x >> y;
    // if(x > y) cout << abs(x-y) << endl;
    cout << rec(x,y) << endl;
}
#include <stdio.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <iostream>

using namespace std;

int main(){
    long x,y;
    scanf("%ld %ld", &x, &y);
    long nAns = abs(x-y);
    long nTmp = 0;
    while (y>x) {
        if (y%2 == 0) {
            y /= 2;
            nTmp++;
        } else {
            nAns = min(nAns, nTmp+2+abs((2*x-y)/2));
            y = (y+1)/4;
            nTmp += 3;
        }
        nAns = min(nAns, nTmp+abs(x-y));
    }
    
    printf("%ld", nAns);  
    
    return 0;
}
