#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;

ll solve(ll y, ll x, unordered_map<ll, ll> &mp)
{
    if(mp.find(y)!=mp.end())
        return mp[y];
        
    if(x>=y)
        return x-y;
    
    if(y%2==0)
    {
        ll temp = min(1 + solve(y/2, x, mp), y-x);
        mp[y] = temp;
        return temp;
    }
    else
    {
        ll temp = min(2 + min(solve((y-1)/2, x, mp), solve((y+1)/2, x, mp)), y-x);
        mp[y] = temp;
        return temp;
    }
}

int main()
{
    ll x, y;
    cin>>x>>y;
    unordered_map<ll, ll> mp;
    cout<<solve(y, x, mp)<<endl;
}

#include <bits/stdc++.h>
//#include <chrono>
#pragma GCC optimize("Ofast")
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()

using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;

ll N,M,H,W,Q,K,A,B;
string S;
using P = pair<ll, ll>;
const ll INF = (1LL<<60);

template<class T> bool chmin(T &a, const T &b){
    if(a > b) {a = b; return true;}
    else return false;
}
template<class T> bool chmax(T &a, const T &b){
    if(a < b) {a = b; return true;}
    else return false;
}
template<class T> void my_printv(std::vector<T> v,bool endline = true){
    if(!v.empty()){
        for(std::size_t i{}; i<v.size()-1; ++i) std::cout<<v[i]<<" ";
        std::cout<<v.back();
    }
    if(endline) std::cout<<std::endl;
}

ll dfs(ll d, int num, bool minus, mat &dp, mat &visited){
    assert(d < (1LL<<(num + 1)));
    if(num < 0) return (d == 0 ? 0 : INF);
    if(visited[num][minus]) return dp[num][minus];
    visited[num][minus] = true;
    ll &res = dp[num][minus];
    if((d>>num)&1) {
        chmin(res, dfs(d - (1LL << num), num - 1, minus, dp, visited) + 1);
    }else {
        if(d != 0) chmin(res, dfs((1LL << num) - d, num - 1, !minus, dp, visited) + 1);
        chmin(res, dfs(d, num - 1, minus, dp, visited));
    }
    return res;
}

ll solve(int num){
    ll res = num;
    ll from = N<<num, to = K, dif = abs(from - to), plus_max = 1LL<<num;
    res += dif / plus_max;
    dif %= plus_max;
    mat dp(num, vec(2, INF)), visited(num, vec(2, false));
    assert(dif < (1LL<<num));
    return res + dfs(dif, num - 1, false, dp, visited);
}

void solve(){
    ll res = abs(N - K);
    for(int i = 0; (N<<i) < (1LL<<62); ++i){
        chmin(res, solve(i));
    }
    cout<<res<<endl;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cin>>N>>K;
    solve();
}
