#include <cstdio>
#include <queue>
#include <cstring>
using namespace std;
int n = 0, m = 0;
int check[100001];
int bfs(int x) {
	queue<int> q;
	check[x] = 0;
	q.push(x);
	int curr = 0, next = 0;
	while (!q.empty()) {
		curr = q.front(); q.pop();
		if (curr == m) return check[m];
		next = curr + 1;
		if (0 <= next && next <= 100000 && check[next] == -1) {
			check[next] = check[curr] + 1;
			q.push(next);
		}
		next = curr - 1;
		if (0 <= next && next <= 100000 && check[next] == -1) {
			check[next] = check[curr] + 1;
			q.push(next);
		}
		next = curr * 2;
		if (0 <= next && next <= 100000 && check[next] == -1) {
			check[next] = check[curr] + 1;
			q.push(next);
		}
	}
}
int main(void) {
	memset(check, -1, sizeof(check));
	scanf("%d%d", &n, &m);
	printf("%d\n", bfs(n));
	return 0;
}