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

map<long long, long long> mp;

ll solve(ll x, ll y){
    if(x == y)return 0;
    if(y < x){
        return abs(x - y);
    }

    if(mp[y] != 0){
        //cout << y << " " << dp[y] << endl;  
        return mp[y];
    }

    //cout << y << endl;
    ll z = abs(x - y);
    if(y%2 == 0){
        mp[y] = min(z, solve(x, y/2) + 1);
        return mp[y];
    }
    else{
        mp[y] = min(z, min(solve(x, y-1) + 1, solve(x, y+1) + 1));
        return mp[y];
    }
}

int main(){
    ll x, y;
    cin >> x >> y;
    
    ll ans = abs(x - y);
    ll s = solve(x, y);
    cout << min(s, ans) << endl;
    return 0;
}
/*
少加头文件，爆零两行泪
DP后效性，爆零两行泪
文件读入错，爆零两行泪
文件名写错，爆零两行泪
调完不编译，爆零两行泪
结论不证明，爆零两行泪
数组没开够，爆零两行泪
ll开 int，爆零两行泪
 dp 没初值，爆零两行泪
深搜没边界，爆零两行泪
广搜忘出队，爆零两行泪
模数没看清，爆零两行泪
越界不特判，爆零两行泪
多测不清空，爆零两行泪
空间胡乱开，爆零两行泪
无向变有向，爆零两行泪
调试忘删除，爆零两行泪
文件不保存，爆零两行泪
题目提交错，爆零两行泪
*/
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#define int long long
#define gmax(x,y) x=max(x,y)
#define gmin(x,y) x=min(x,y)
#define F first
#define S second
#define P pair
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define V vector
#define RE return
#define ALL(a) a.begin(),a.end()
#define MP make_pair
#define PB emplace_back
#define PF emplace_front
#define FILL(a,b) memset(a,b,sizeof(a))
#define lwb lower_bound
#define upb upper_bound
using namespace std;
int dp[65][2];
bool fa[65],fb[65];
int geta(int l,int r){
	int re=0;
	FOR(i,l,r){
		re=re*2+fa[i];
	}
	RE re;
}
int getb(int l,int r){
	int re=0;
	FOR(i,l,r){
		re=re*2+fb[i];
	}
	RE re;
}
void solve(int i){
	gmin(dp[i][0],dp[i-1][1]+2);
	gmin(dp[i][0],dp[i-1][0]+fb[i]+1);
	gmin(dp[i][1],dp[i-1][1]-fb[i]+1+1);
	gmin(dp[i][1],dp[i-1][0]+2);
}
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int a,b;
	cin>>a>>b;
	if(a>=b){
		cout<<a-b;RE 0;
	}
	int la,lb;
	la=lb=0;
	V<int> v;
	while(a){
		v.PB(a&1);
		a/=2;
	}
	while(!v.empty()){
		fa[++la]=v.back();
		v.pop_back();
	}
	while(b){
		v.PB(b&1);
		b/=2;
	}
	while(!v.empty()){
		fb[++lb]=v.back();
		v.pop_back();
	}
	dp[la-1][0]=abs(geta(1,la)-getb(1,la-1));
	dp[la-1][1]=abs(geta(1,la)-(getb(1,la-1)));
	dp[la][0]=abs(geta(1,la)-getb(1,la));
	dp[la][1]=abs((getb(1,la)+1)-geta(1,la));
	gmin(dp[la][0],abs(2*geta(1,la)-getb(1,la))+1);
	gmin(dp[la][1],abs((getb(1,la)+1)-2*geta(1,la))+1);
	solve(la);
	dp[la+1][0]=abs(geta(1,la)-getb(1,la+1));
	dp[la+1][1]=abs((getb(1,la+1)+1)-geta(1,la));
	solve(la+1);
	FOR(i,la+2,lb){
		dp[i][0]=1e18;
		dp[i][1]=1e18;
		solve(i);
	}
	cout<<min(dp[lb][0],dp[lb][1]+1);
	RE 0;
}




