#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <algorithm>
#define LL long long int
#define pii pair<int, int> 
using namespace std;
int n, k, t[100001];
vector<int> v[100001];
bool discovered[100001] = {false};

void bfs(int start){
	queue<int> q;
	discovered[start] = true;
	q.push(start);
	int f = 1;
	while(f){
		int here = q.front();
		q.pop();
		discovered[here] = true;
		
		for(int i=0; i<v[here].size(); i++){
			int there = v[here][i];
			
			if(!discovered[there]){
				q.push(there);
				discovered[there] = true;
				t[there] = t[here] + 1;
				if(there == k){
					cout << t[there] << "\n";
					f = 0;
				}
			}
		}
	}
	
}
int main() {
	ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  
  cin >> n >> k;
  
  for(int i=0; i<=99999; i++) v[i].push_back(i+1);
	for(int i=1; i<=100000; i++) v[i].push_back(i-1);
	for(int i=2; i<=50000; i++) v[i].push_back(2*i);
	
	bfs(n);
	
}