#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cstdint>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define MP make_pair
#define PB push_back
#define inf 1000000007
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
 
template<class T> inline bool chmax(T &a, T b){
    if(a<b){
        a = b;
        return true;
    }
    return false;
}

template<class T> inline bool chmin(T &a, T b){
    if(a>b){
        a = b;
        return true;
    }
    return false;
}
map<pair<ll,ll>,ll> mp;
ll calc(ll a,ll k){
    if(a==0)return 0;
    if(k==0)return a;
    if(mp.find(MP(a,k))!=mp.end())return mp[MP(a,k)];
    ll K = (1LL<<k);
    return mp[MP(a,k)] = min(a/K + calc(a-K*(a/K),k-1), a/K+1 + calc((K)*(a/K + 1)-a,k-1));
}
int main(){
    ll x,y;
    cin >> x >> y;
    ll mi = (1LL<<62);
    for(int i=0;i<=62;i++){
        ll X = x;
        bool ng = 0;
        rep(j,i){
            X *= 2;
            if(X >=4000000000000000000LL){
                ng = 1;
                break;
            }
        }
        if(ng)break;
        ll p = abs(X-y);
        // cerr << i << " " << p << endl;
        ll res = 0;
        res = calc(p,i);
        // for(int j=i;j>=0;j--){
        //     ll K = (1LL<<j);
        //     res += (p/K);

        //     p -= K * (p/K);
        //     ll s = __builtin_popcount(p);
        //     ll q = abs(p-K);
        //     ll t = __builtin_popcount(q);
        //     if(s>t){
        //         p = q;
        //         res++;
        //     }else{

        //     }
        // }
        chmin(mi,res+i);
    }
    cout << mi << endl;
    return 0;
}
#include <bits/stdc++.h>

using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	long long x, y;
	cin >> x >> y;
	map<long long, long long> dp;
	auto sol = [&](auto &&self, long long val){
		if(dp[val]) return dp[val];
		if(x >= val){
			return x - val;
		}
		long long rv = val - x;
		if(val % 2){
			rv = min(rv, self(self, (val - 1) / 2) + 2);
			rv = min(rv, self(self, (val + 1) / 2) + 2);
		}
		else{
			rv = min(rv, self(self, val / 2) + 1);
		}
		dp[val] = rv;
		return rv;
	};
	cout << sol(sol, y);
	return 0;
}