#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define P pair<int,int>

ll cnt(ll y,ll x,map<ll,ll> &data){
  if(data.count(y)){
    return data[y];
  }
  if(x>=y){
    data[y] = x-y;
    return (ll) x-y;
  }
  if(y%2==0){
    ll z = min(cnt(y/2,x,data)+1,abs(y-x));
    data[y] = z; return z;
  }
  else{
    ll z = min(min(cnt(y+1,x,data)+1,abs(y-x)),cnt(y-1,x,data)+1);
    data[y] = z; return z;
  }
}

int main(){
  long long X,Y;
  cin >> X >> Y;
  map<ll,ll> data;
  cout << cnt(Y,X,data) << endl;
}
/*
Nguyen Duc Anh Phuc_Jacke
*/

#include <limits.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <unordered_set>
#include <set>
#include <fstream>
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<ll, pll> plll;

#define fi first
#define se second.first
#define th second.second

map<ll, ll> mp;

ll sol(ll x, ll y)
{
	if (mp[x])
		return mp[x];

	if (x == y)
	{
		mp[x] = 0;
		return 0;
	}
	if (x / 2 == y && x % 2 == 0 )
	{
		mp[x] = 1;
		return 1;
	}
	if (x / 2 < y)
	{
		if (x % 2 == 0)
			return mp[x]=min(x - y, y - x / 2 + 1);
		else
			return mp[x]=min(x - y, min(y - x / 2 + 2, (y - (x / 2 + 1) + 2)));
	}

	ll le = LLONG_MAX;
	ll ri = LLONG_MAX;
	if (x % 2 == 0)
	{
		le = sol(x / 2, y) + 1;
	}
	else
	{
		le = sol(x / 2, y) + 2;
		ri = sol(x / 2 + 1, y) + 2;
	}
	return mp[x]=min(le, ri);
}

int main()
{
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	ll x, y;
	cin >> x >> y;
	if (x >= y)
	{
		cout << x - y;
		return 0;
	}
	cout << sol(y, x);
	return 0;
}