/* Hardwork allways pays off */
//You never know how close to the solution you are ,so keep practicing
#include <bits/stdc++.h>
using namespace std;
#define int long long  
#define ld long double
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define endl '\n'
#define REP(i,n) for(int i=1;i<=n;i++)
#define tol(s) transform(s.begin(),s.end(),s.begin(),::tolower)
#define tou(s) transform(s.begin(),s.end(),s.begin(),::toupper)
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define all(x) (x).begin(), (x).end()
#define mod1 998244353 
#define mod 1000000007 
#define pie 3.141592653589793238
#define printv(x) for(i=0;i<x.size();i++) cout<<x[i]<<" ";
#define printA(x,n) for(i=0;i<n;i++) cout<<x[i]<<" ";
void make_unique(vector<int> vec)
{
sort(all(vec));
vec.resize(unique(all(vec)) - vec.begin());
}

bool isPowerOfTwo(int n)
{
   if(n==0)
   return false;
 
   return (ceil(log2(n)) == floor(log2(n)));
}
int cceil(int x, int y){
    return (x+y-1)/y;
}
bool cmp(const pair<int,int> &a,
                   const pair<int,int> &b)
{
       return (a.second+a.first)>(b.second+b.first);
}
int x,y;
int ans=1e18;
// int dp[]
map<int,int> dp,vis;
// int count=0;
int repeat(int y)   //return min steps to reach x from y by -1,+1,/2
{   
    // cout<<y<<endl;
    // ans=abs(y-x);
    if(vis[y])
        return dp[y];
    vis[y]=1;
    dp[y]=1e18;
    int &ans=dp[y];
    ans=min(ans,abs(y-x)); 
    if(y==1)
        return ans;
    else if(y<x)
        return x-y;
    else 
    {
        if(y%2==0)  
            ans= min(ans,(1+repeat(y/2)));
        else
        {
            ans= min(ans,1+min(repeat(y-1),repeat(y+1)));
        }
    }
    return ans;

}
signed main() 
 {   ios;
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin); 
    freopen("output.txt", "w", stdout);
    #endif
    // cout.precision(1);
    // cout<<fixed;
    int t=1;
     // cin>>t; 
    while(t--)
    {int n,k,i,m,j,flag=1,moves=0,count=0;
       // cin>>n;
        // int x,y;
        cin>>x>>y;
        if(x>=y)
            cout<<x-y<<endl;
        else
        {
            int ans=repeat(y);
            cout<<ans<<endl;
        }
        
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> pi;
#define f first
#define s second
#define FAST ios_base::sync_with_stdio(0); cin.tie(0);
#define all(x) x.begin(),x.end()
typedef pair<int, pi> pii;

const int maxn = 500010;
const int INF = LLONG_MAX/2;

int x, Y;

map <int, int> dp;
int dpf(int y) {
	if (y <= x) return x - y;
	if (dp.find(y) != dp.end()) return dp[y];
	
	if (y % 2 == 0) {
		if (y/2 >= x) dp[y] = dpf(y/2) + 1;
		else dp[y] = min(x - y/2 + 1, y - x);
	} else {
		dp[y] = 1 + min(dpf(y+1), dpf(y-1));
	}
	return dp[y];	
}

int32_t main() {
	FAST
	cin >> x >> Y;
	
	cout << dpf(Y);
}







