
// Problem : F - +1-1x2
// Contest : AtCoder - AtCoder Beginner Contest 188
// URL : https://atcoder.jp/contests/abc188/tasks/abc188_f
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cp-editor)

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

#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define endl '\n'
#define vi vector<ll>
#define pii pair<ll, ll>
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define fill(a,b) memset(a, b, sizeof(a))
#define setbits(x) __builtin_popcountll(x)

const ll inf=0x3f3f3f3f3f3f3f3f;
ll x, y;
map<pii, ll> dp;
ll call(ll m, ll n) {
	if(m >= n)return m - n;
	if(dp.find({m, n}) != dp.end())return dp[{m, n}];
	ll rtn = n - m;
	if(n % 2) {
		rtn = min(rtn, 1 + call(m, n + 1));
		rtn = min(rtn, 1 + call(m, n - 1));
	}
	else {
		rtn = min(rtn, 1 + call(m, n / 2));
	}
	return dp[{m, n}] = rtn;
}

int main() {
    SPEED;
    cin>>x>>y;
    cout<<call(x, y);
    return 0;
}
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
#define forn(i,a,b)for(int i=(a),_b=(b);i<=_b;i++)
#define fore(i,b,a)for(int i=(b),_a=(a);i>=_a;i--)
#define rep(i,n)for(int i=0,_n=n;i<n;i++)
#define ll long long
#define pii pair<int,int>
#define vi vector<int>
#define vpii vector<pii>
#define m_p make_pair
#define re return
#define pb push_back
#define si set<int>
#define ld long double
#define X first
#define Y second
#define st string
#define ull unsigned long long
#define mod 1000000007
#define INF 1000000007
#define x1 XZVJDFADSPFOE
#define y1 GASDIJSLDAEJF
#define x2 DFDAJKVOHKWIW
#define y2 PSFSAODSXVNMQ
#define LLINF 0x3f3f3f3f3f3f3f3fLL
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
using namespace std;
inline void read(int &x)
{
	short negative=1;
    x=0;
    char c=getchar();
    while(c<'0' || c>'9')
    {
		if(c=='-')
			negative=-1;
		c=getchar();
	}
    while(c>='0' && c<='9')
        x=(x<<3)+(x<<1)+(c^48),c=getchar();
    x*=negative;
}
ll quickpower(ll n,ll k){
	ll ans=1;
	while(k){
		if(k%2){
			ans*=n;
			ans%=mod;
		}
		n*=n;
		n%=mod;
		k/=2;
	}
	return ans;
}
string int_to_string(int n)
{
	string s="";
	while(n)
	{
		int now=n%10;
		s+=now+'0';
		n/=10;
	}
	reverse(s.begin(),s.end());
	return s;
}
int string_to_int(string s)
{
	int n=0;
	rep(i,s.size())
	{
		n*=10;
		n+=s[i]-'0';
	}
	return n;
}
ll x,y;
map<ll,ll>mp;
map<ll,bool>used;
int main()
{
	ios::sync_with_stdio(0);
	cin>>x>>y;
	if(y<=x)
	{
		cout<<x-y<<endl;
		return 0;
	}
	queue<ll>q;
	q.push(y);
	ll mn=1e18+1;
	while(!q.empty())
	{
		ll now=q.front();
		q.pop();
	//	cout<<now<<" "<<mp[now]<<endl;
		used[now]=1;
		if(now==0)break;
		mn=min(mn,abs(now-x)+mp[now]);
		if(now%2==0)
		{
			if(mp[now/2]==0)mp[now/2]=mp[now]+1;
			else mp[now/2]=min(mp[now/2],mp[now]+1);
			if(!used[now/2])q.push(now/2);
		}	
		{
			if(mp[now-1]==0)mp[now-1]=mp[now]+1;
			else mp[now-1]=min(mp[now-1],mp[now]+1);
			if(mp[now+1]==0)mp[now+1]=mp[now]+1;
			else mp[now+1]=min(mp[now+1],mp[now]+1);
			if(!used[now-1]&&now%2==1)q.push(now-1);
			if(!used[now+1]&&now%2==1)q.push(now+1);
		}
	}
	ll ans=mn;
	if(mp[x]!=0)cout<<mp[x]<<endl;
	else cout<<ans<<endl;
	return 0;
}
