#include <algorithm>
#include <array>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <utility>
#include <vector>
#include <stack>
using namespace std;
using ll = long long int;
// fast IO
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
////////// 	Template structure for debugging
#define tr(...) trace(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void trace(const char* name, Arg1&& arg1){
  cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void trace(const char* names, Arg1&& arg1, Args&&... args){
  const char *comma = strchr(names + 1, ',');
  cout.write(names, comma - names) << " : " << arg1 << " | ";
  trace(comma + 1, args...);
}
#define print(...) pr(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void pr(const char* name, Arg1&& arg1){
  cout << arg1 << endl;
}
template <typename Arg1, typename... Args>
void pr(const char* names, Arg1&& arg1, Args&&... args){
  const char *comma = strchr(names + 1, ',');
  cout << arg1 << " ";
  pr(comma + 1, args...);
}
void printV(vector<int> &arr)
{
	cout << "Vector : ";
	for(int i=0;i<arr.size();i++)
		cout << arr[i] << " \n"[ i == arr.size()-1 ];
}
void printV(vector<long long> &arr)
{
	cout << "Vector : ";
	for(int i=0;i<arr.size();i++)
		cout << arr[i] << " \n"[ i == arr.size()-1 ];
}
void printA(int arr[], int n) {
  cout << "Array : ";
  for (int i = 0; i < n; i++)
	cout << arr[i] << " \n"[i == n - 1];
}

/////////////////////////////////////////////////////////////////////////////
////////////////////// DO NOT TOUCH BEFORE THIS LINE ////////////////////////
/////////////////////////////////////////////////////////////////////////////


ll x, y;
map<ll, ll> m;
ll ans = 1e18;
ll find(ll target, ll curr){
	if(curr == target)return 0;
	if(m.count(curr)) return m[curr];
	m[curr] = abs(curr - target);
	ll &ans = m[curr];
	if(curr == 1)return ans;
	if(curr % 2 == 0)ans = min(1 + find(target, curr/2), ans);
	else ans = min(ans,1 + min(find(target, curr + 1), find(target, curr - 1)));
	return ans;
}
void solve(int tc = 1){
	cin >> x >> y;
	cout << find(x, y) << endl;
}

int main(){
	IOS;
	int tt = 1;
	//cin >> tt;
	while(tt--)solve();
}

#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-12;

//int N, M, K, T, H, W, L, R;
long long int N, M, K, T, H, W, L, R;


int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);


	cin >> N >> M;
	if (N >= M) {
		cout << N - M << endl;
		return 0;
	}
	long long int ans = MOD*MOD;
	for (int i = 0; i <= 62; i++) {
		if ((N << i) > 4e18)break;
		long long int dif = abs((N << i) - M);
		long long int cnt = i + dif / (1LL << i);
		dif %= (1LL << i);
		vector<vector<int>>dp(i + 2, vector<int>(3, MOD));
		dp[0][1] = 0;
		for (int j = 0; j <= i; j++) {
			for (int k = 0; k < 3; k++) {
				long long int b = dif >> j & 1;
				long long int st = b + k - 1;
				if (st == -1) {
					dp[j + 1][0] = min(dp[j + 1][0], dp[j][k] + 1);
					dp[j + 1][1] = min(dp[j + 1][1], dp[j][k] + 1);
				}
				else if (st == 0) {
					dp[j + 1][1] = min(dp[j + 1][1], dp[j][k]);
				}
				else if (st == 1) {
					dp[j + 1][1] = min(dp[j + 1][1], dp[j][k] + 1);
					dp[j + 1][2] = min(dp[j + 1][2], dp[j][k] + 1);
				}
				else if (st == 2) {
					dp[j + 1][2] = min(dp[j + 1][2], dp[j][k]);
				}
			}
		}
		ans = min(ans, cnt + dp[i + 1][1]);
	}
	cout << ans << endl;
}