Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number n.

Bob wants to get number m on the display. What minimum number of clicks he has to make in order to achieve this result?


-----Input-----

The first and the only line of the input contains two distinct integers n and m (1 ≤ n, m ≤ 10^4), separated by a space .


-----Output-----

Print a single number — the minimum number of times one needs to push the button required to get the number m out of number n.


-----Examples-----
Input
4 6

Output
2

Input
10 1

Output
9



-----Note-----

In the first example you need to push the blue button once, and then push the red button once.

In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.

Source: codeforces | Difficulty: MEDIUM
Tags: Graph algorithms

Graph traversal

Shortest paths

Implementation

Greedy algorithms

Mathematics


Solutions:
from math import *
nums = input().split()
n = int(nums[0])
m = int(nums[1])

def mincount(n, m):
	count = 0
	if n > m:
		count = n - m
	elif n < m:
		if m % 2 == 0:
			count = mincount(n, m // 2) + 1
		if m % 2 == 1:
			count = mincount(n, m + 1) + 1
	return count
print(mincount(n, m))


(initial, end) = [int(a) for a in input().split()]
total = 0
if initial > end:
	total = initial - end
else:
	total = 0
	while end > initial:
		if end % 2 == 0:
			end //= 2
		else:
			end += 1
		total += 1
	total += initial - end
print(total)


(n, m) = map(int, input().split())
sol = 0
while n < m:
	sol += 1 + m % 2
	m = (m + m % 2) / 2
sol += n - m
print(int(sol))


(n, m) = [int(x) for x in input().split()]
if n >= m:
	print(n - m)
else:
	count = 0
	while n != m:
		if n < m:
			if m % 2 == 0:
				m = m / 2
			else:
				m = m + 1
			count += 1
		else:
			count += n - m
			n = m
	print('{0:.0f}'.format(count))


is_debug = False
from collections import deque
(n, m) = map(int, input().split())
q = deque()
q.append(m)
d = [-1] * 1000000
d[m] = 0
c = 0
while True:
	v = q.popleft()
	print(f'v={v}, q={q}') if is_debug else ''
	if v == n:
		c = d[v]
		break
	elif v < 0:
		continue
	v1 = v // 2
	v2 = v + 1
	if v1 < 1000000 and d[v1] == -1 and (v1 * 2 == v):
		d[v1] = d[v] + 1
		q.append(v1)
	if v2 < 1000000 and d[v2] == -1:
		d[v2] = d[v] + 1
		q.append(v2)
print(f'{c}')


(n, m) = map(int, input().split())
if n > m:
	print(n - m)
	exit(0)
c = 0
while n < m:
	if m % 2 == 0:
		m = m / 2
	else:
		m += 1
	c += 1
print(int(c + n - m))


def run():
	(nn, mm) = input().split()
	n = int(nn)
	m = int(mm)
	counter = 0
	while n != m:
		if m % 2 == 1 or m < n:
			m += 1
		else:
			m /= 2
		counter += 1
	print(counter)
run()


def solve(n, m):
	if n >= m:
		return n - m
	elif m % 2 == 0:
		if m / 2 < n:
			return n - m // 2 + 1
		elif m / 2 > n:
			return 1 + solve(n, m // 2)
		else:
			return 1
	else:
		return 1 + solve(n, m + 1)
(a, b) = map(int, input().split())
print(solve(a, b))


import math
import sys

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
(displayed, target) = map(int, input().split())

def two_buttons(displayed, target):
	if displayed >= target:
		return displayed - target
	elif target % 2 == 0:
		return 1 + two_buttons(displayed, target / 2)
	else:
		return 2 + two_buttons(displayed, (target + 1) / 2)
print(int(two_buttons(displayed, target)))


(a, b) = map(int, input().split())
s = 0
while b > a:
	if b % 2 == 0:
		b //= 2
	else:
		b += 1
	s += 1
print(a - b + s)


(n, m) = map(int, input().split())
count = 0
while m > n:
	if m % 2 == 0:
		m = m // 2
	else:
		m += 1
	count += 1
while m < n:
	m += 1
	count += 1
print(count)


import collections

def bfs(graph, root, elem):
	cou = collections.defaultdict(int)
	(visited, que) = (set(), collections.deque([root]))
	while que:
		vertex = que.popleft()
		for neigh in graph[vertex]:
			if neigh not in visited:
				visited.add(neigh)
				que.append(neigh)
				cou[neigh] = cou[vertex] + 1
			if neigh == elem:
				return cou
(n, m) = map(int, input().split())
if n == m:
	print(0)
elif n > m:
	print(n - m)
else:
	graph = collections.defaultdict(list)
	for t in range(1, 2 * m + 1):
		graph[t].append(t - 1)
		graph[t].append(t * 2)
	p = bfs(graph, n, m)
	p = list(p.values())
	print(p[-1])


(n, m) = map(int, input().split())
vis = [-1] * 20000
q = [0] * 20000
tail = 1
q[0] = n
vis[n] = 0
on = 0
while on < tail:
	cur = q[on]
	on += 1
	if cur + cur < 20000 and vis[cur + cur] == -1:
		vis[cur + cur] = 1 + vis[cur]
		q[tail] = cur + cur
		tail += 1
	if cur - 1 > 0 and vis[cur - 1] == -1:
		vis[cur - 1] = 1 + vis[cur]
		q[tail] = cur - 1
		tail += 1
print(vis[m])


from sys import setrecursionlimit
from collections import deque
setrecursionlimit(1000000000)
(n, m) = map(int, input().split())
if n > m:
	print(n - m)
else:
	a = [-1 for i in range(2 * m + 2)]
	a[n] = 0
	q = deque()
	q.append(n)
	while len(q) != 0:
		v = q.popleft()
		if v == m:
			print(a[v])
			exit(0)
		if v > 1 and a[v - 1] == -1:
			q.append(v - 1)
			a[v - 1] = a[v] + 1
		if v <= m and a[2 * v] == -1:
			q.append(2 * v)
			a[2 * v] = a[v] + 1


(n, m) = map(int, input().split())
q = [n]
b = 1
r = 0
i = 0
used = [False] * (2 * 10 ** 4 + 10)
used[n] = True
while i < len(q):
	if i == b:
		b = len(q)
		r += 1
	if q[i] == m:
		print(r)
		break
	if q[i] > 1:
		if not used[q[i] - 1]:
			q.append(q[i] - 1)
			used[q[i] - 1] = True
	if q[i] < m:
		if not used[q[i] * 2]:
			q.append(q[i] * 2)
			used[q[i] * 2] = True
	i += 1


(n, m) = [int(x) for x in input().strip().split()]
if m <= n:
	print(n - m)
else:
	end = m + 1 if m % 2 else m
	dp = [n - i if i <= n else 0 for i in range(end + 1)]
	if n % 2:
		dp[n + 1] = dp[int((n + 1) / 2)] + 1
		start = n + 3
	else:
		start = n + 2
	for i in range(start, end + 1, 2):
		dp[i] = dp[int(i / 2)] + 1
		dp[i - 1] = dp[i] + 1
	print(dp[m])


arr = list(map(int, input().rstrip().split()))
n = arr[0]
m = arr[1]
ans = 0
while m > n:
	if m % 2 == 0:
		m //= 2
	else:
		m += 1
	ans += 1
print(ans + n - m)


(n, m) = map(int, input().split())
cnt = 0
while 1:
	if m <= n:
		cnt += n - m
		break
	if m % 2:
		cnt += 1
		m += 1
	m //= 2
	cnt += 1
print(cnt)


import math
instr = input()
space = instr.find(' ')
inint = int(instr[:space])
outint = int(instr[space + 1:])
nowhalf = outint
counts = 0
adds = 0
while True:
	if inint >= nowhalf:
		print(int(inint - nowhalf + counts + adds))
		break
	counts += 1
	pasthalf = nowhalf
	nowhalf = math.ceil(nowhalf / 2)
	if nowhalf * 2 > pasthalf:
		adds += 1


from collections import defaultdict
(n, m) = list(map(int, input().split()))
working_list = []
working_list.append(n)
flag = 0
level = 0
visited = defaultdict(int)
while len(working_list) != 0:
	l = []
	for i in range(len(working_list)):
		if not visited[working_list[i]]:
			visited[working_list[i]] = 1
			if working_list[i] == m:
				flag = 1
				break
			if working_list[i] > m:
				l.append(working_list[i] - 1)
			else:
				if working_list[i] - 1 > 0:
					l.append(working_list[i] - 1)
				l.append(working_list[i] * 2)
	if flag == 1:
		break
	working_list = l
	level += 1
print(level)


(n, m) = map(int, input().split())
r = [0] * 10 ** 5
r[n] = 1
t = [n]
i = 0
while t[i] != m:
	a = t[i]
	if a * 2 < 10 ** 5 and r[a * 2] == 0:
		r[a * 2] = r[a] + 1
		t.append(a * 2)
	if a and r[a - 1] == 0:
		r[a - 1] = r[a] + 1
		t.append(a - 1)
	i += 1
print(r[m] - 1)


s = input().split()
n = int(s[0])
m = int(s[1])
ans = 0
while m > n:
	if m % 2 == 0:
		m = m / 2
		ans += 1
	else:
		m += 1
		ans += 1
print(int(ans + (n - m)))


from math import ceil
(n, m) = list(map(int, input().split()))
step = 0
if n >= m:
	step += n - m
else:
	k = m
	while n < k:
		k = k / 2
	while n != m:
		if n - 1 >= k:
			n -= 1
			step += 1
		else:
			k = 2 * k
			n = 2 * n
			step += 1
print(step)


def find_path_count(x, y):
	if x == y:
		return 0
	paths = {x: 0}
	count = x * y
	max_t = 2 * y
	cur_i = -1
	results = []
	while True:
		new_items = {}
		cur_i += 1
		for (t, v) in paths.items():
			temps = (t - 1, t * 2)
			for temp in temps:
				if temp == y:
					return v + 1
				if temp not in paths:
					if temp > 1:
						if temp > y:
							count = min(count, temp - y + v + 1)
							continue
						new_items[temp] = v + 1
		paths = new_items
		if cur_i >= count:
			return count
(x, y) = map(int, input().split(' '))
print(find_path_count(x, y))


from array import array
INF = 10 ** 9
(n, m) = map(int, input().split())
a = array('L')
a.extend((INF for i in range(max(m * 3, n + 1))))
for i in range(n):
	a[i + 1] = n - i - 1
for i in range(1, m + 1):
	if a[i] < a[i * 2]:
		a[i * 2] = a[i] + 1
		j = i * 2 - 1
		while j >= 0 and a[j] > a[j + 1]:
			a[j] = a[j + 1] + 1
			j -= 1
print(a[m])


(n, m) = [int(n) for n in input().split()]
count = 0
while n != m:
	if m < n:
		count += n - m
		break
	elif m % 2 == 0:
		m /= 2
	else:
		m += 1
		m /= 2
		count += 1
	count += 1
print(int(count))


(n, m) = [int(i) for i in input().split(' ')]
times_ = 0
minus_ = 0
while n < m:
	if m % 2 == 0:
		m = int(m / 2)
	else:
		m = m + 1
	times_ += 1
print(times_ + (n - m))


from sys import stdin, stdout
from collections import defaultdict
import heapq

def get_int():
	return int(stdin.readline().strip())

def get_ints():
	return map(int, stdin.readline().strip().split())

def get_array():
	return list(map(int, stdin.readline().strip().split()))

def get_string():
	return stdin.readline().strip()
INF = 10000000000.0
(n, m) = get_ints()
c = 0
while n != m:
	if n > m:
		m += 1
		c += 1
	elif n < m:
		if m % 2 == 0:
			m = m // 2
			c += 1
		else:
			m += 1
			c += 1
print(c)


(n, m) = map(int, input().split())
if n > m:
	print(n - m)
else:
	ans = 0
	while n != m:
		if m % 2 != 0 or m < n:
			m += 1
			ans += 1
		else:
			m = m // 2
			ans += 1
	print(ans)


from sys import stdin
max_val = int(10000000000000.0)
min_val = int(-10000000000000.0)

def read_int():
	return int(stdin.readline())

def read_ints():
	return [int(x) for x in stdin.readline().split()]

def read_str():
	return input()

def read_strs():
	return [x for x in stdin.readline().split()]
(has, need) = read_ints()
ops = 0
while has != need:
	ops += 1
	if need < has or need % 2 == 1:
		need += 1
	else:
		need //= 2
print(ops)


(n, m) = map(int, input().split(' '))

def solve(n, m):
	steps = 0
	while m != n:
		if n < m:
			if m % 2 == 0:
				m /= 2
			else:
				m += 1
		elif n > m:
			m += 1
		steps += 1
	return steps
print(solve(n, m))


from collections import defaultdict
(x, y) = map(int, input().split())
s = 0
while x != y:
	if x >= y:
		s += x - y
		break
	elif y % 2 == 0:
		s += 1
		y //= 2
	elif y % 2 == 1:
		s += 2
		y = (y + 1) // 2
print(s)


(n, m) = [int(x) for x in input().split()]
c = 0
if m < n:
	print(n - m)
else:
	while m > n:
		if m % 2 == 0:
			m //= 2
			c += 1
		else:
			m += 1
			c += 1
	print(abs(c + n - m))


def get_num_of_steps(start_num, target_num):
	upper_bound = start_num
	while upper_bound < target_num:
		upper_bound *= 2
	visited = [False] * (upper_bound + 1)
	visited[start_num] = True
	queue = [(start_num, 0)]
	min_steps = None
	while len(queue) != 0:
		(head, steps) = queue[0]
		queue = queue[1:]
		if head < target_num:
			if 2 * head <= upper_bound and (not visited[2 * head]):
				visited[2 * head] = True
				queue.append((2 * head, steps + 1))
			if head >= 1 and (not visited[head - 1]):
				visited[head - 1] = True
				queue.append((head - 1, steps + 1))
		elif head > target_num:
			num_steps = steps + head - target_num
			if min_steps is None or num_steps < min_steps:
				min_steps = num_steps
		elif min_steps is None or steps < min_steps:
			min_steps = steps
	return min_steps

def solve():
	line = input()
	(start_num, target_num) = [int(num) for num in line.split()]
	num_of_steps = get_num_of_steps(start_num, target_num)
	print(num_of_steps)
solve()


import math, sys

def func(n, m):
	if n == m:
		return 0
	if n > m:
		return n - m
	else:
		acc = 0
		if m % 2 == 1:
			m += 1
			acc += 1
		m = m // 2
		return acc + 1 + func(n, m)
(n, m) = map(int, input().split())
print(func(n, m))


(n, m) = map(int, input().split())
s = 0
if n > m:
	print(n - m)
else:
	while n != m:
		if m % 2 == 0 and m / 2 > n / 2:
			m = m / 2
		else:
			m = m + 1
		s = s + 1
	print(s)


import math
(n, m) = map(int, input().split(' '))
mlist = [m]
if m == 1:
	mList = [1]
else:
	while m > 1:
		mlist.append(math.ceil(m / 2))
		m = math.ceil(m / 2)
ops = 0
while n != mlist[0]:
	for i in range(len(mlist)):
		if mlist[i] <= n:
			target = mlist[i]
			break
	while n > target:
		n -= 1
		ops += 1
	if n == target and target != mlist[0]:
		n = n * 2
		ops += 1
print(ops)


(n, m) = [int(i) for i in input().split()]
from collections import Counter

def findPath(goal):
	explore = set()
	explore.add((n, 1))
	new_set = set()
	while True:
		curr = explore.pop()
		if curr[0] == goal:
			return curr[1]
		elif curr[0] == 1:
			new_set.add((curr[0] * 2, curr[1] + 1))
		elif curr[0] > goal:
			new_set.add((curr[0] - 1, curr[1] + 1))
		else:
			new_set.add((curr[0] - 1, curr[1] + 1))
			new_set.add((curr[0] * 2, curr[1] + 1))
		if len(explore) < 1:
			smaller_list = [el for el in new_set if el[0] < goal]
			big_list = [el for el in new_set if el[0] >= goal]
			if len(big_list) > 1:
				min_of_big = min(big_list, key=lambda tuple: tuple[0])
				big_list = [min_of_big]
			explore = explore.union(smaller_list).union(big_list)
			new_set = set()
	return -1
print(findPath(m) - 1)


def fun(n, m):
	moves = 0
	if n > m:
		print(abs(n - m))
		exit()
	while n != m:
		if m % 2 == 0 and m > n:
			m /= 2
			moves += 1
		else:
			m += 1
			moves += 1
	return moves
(n, t) = map(int, str(input()).split(' '))
print(fun(n, t))


(n, m) = [int(x) for x in input().split()]
t = 0

def wh(m):
	global t
	if m % 2 == 0:
		m = m / 2
		t = t + 1
	else:
		m = (m + 1) / 2
		t = t + 2
	if m > n:
		wh(m)
	else:
		t = t + n - m
		print(int(t))
if n >= m:
	print(n - m)
else:
	wh(m)


(a, b) = map(int, input().split())
if a >= b:
	print(a - b)
else:
	op = 0
	while b != a:
		if b < a:
			op += a - b
			break
		if b % 2 != 0:
			b += 1
		else:
			b = b // 2
		op += 1
	print(op)


def main():
	(n, m) = map(int, input().split())
	print(rec(n, m))

def rec(n, m):
	if m <= n:
		return n - m
	elif m % 2:
		return rec(n, m + 1) + 1
	else:
		return rec(n, m // 2) + 1
main()


from collections import deque

def possibleValues(current, need):
	seen = [False for _ in range(20001)]
	queue = deque([[current, 0]])
	next = queue.popleft()
	while next[0] != need:
		if not seen[next[0]]:
			if next[0] >= 1:
				queue.append([next[0] - 1, next[1] + 1])
			if next[0] < need:
				queue.append([next[0] * 2, next[1] + 1])
			seen[next[0]] = True
		next = queue.popleft()
	return next[1]
(current, need) = list(map(int, input().split(' ')))
print(possibleValues(current, need))


(n, m) = map(int, input().split())
a = 0
while m > n:
	a += 1 + (m & 1)
	m = (m + (m & 1)) // 2
print(a + n - m)


from collections import deque

def get_children(node):
	(num, depth) = node
	return ((2 * num, depth + 1), (num - 1, depth + 1))
(n, m) = map(lambda x: int(x), input().split())
q = deque()
visited = set()
if n > m:
	print(n - m)
else:
	q.appendleft((n, 0))
	while q:
		cur_node = q.pop()
		if cur_node[0] == m:
			print(cur_node[1])
			break
		for child in get_children(cur_node):
			if child[0] not in visited and child[0] > 0:
				if child[0] > m and cur_node[0] > m:
					continue
				q.appendleft(child)
				visited.add(child[0])


import sys
from math import sqrt, gcd, ceil, log
from collections import defaultdict, Counter, deque
input = sys.stdin.readline
read = lambda : list(map(int, input().strip().split()))

def main():
	(n, m) = read()
	ans = 0
	while n < m:
		ans += 1 + m % 2
		m = m // 2 + m % 2
	print(ans + n - m)
main()


(inicial, final) = list(map(int, input().split()))
if inicial >= final:
	print(int(inicial - final))
else:
	retorno = 0
	aux = final
	while aux > inicial:
		if not aux % 2 == 0:
			aux += 1
			retorno += 1
		aux = aux / 2
		retorno += 1
	retorno += inicial - aux
	print(int(retorno))


(a, b) = map(int, input().split())
cnt = 0
while a != b:
	if a > b or b % 2:
		b += 1
	else:
		b /= 2
	cnt += 1
print(cnt)


from math import floor

def minop(x, y):
	if x == y:
		return 0
	if x > y:
		return x - y
	if x <= 0 and y > 0:
		return -1
	if y % 2:
		return 1 + minop(x, y + 1)
	else:
		return 1 + minop(x, y / 2)
(m, n) = map(int, input().split())
c = 0
grab = minop(m, n)
if grab - floor(grab) == 0:
	print(int(grab))


(n, m) = map(int, input().split())
ans = 0
while n < m:
	ans += 1 + m % 2
	m = (m + m % 2) // 2
print(ans + n - m)


(n, m) = list(map(int, input().split()))
if m <= n:
	print(n - m)
else:
	memo = [0] * (m + 1)
	i = 0
	while i <= n:
		memo[i] = n - i
		i = i + 1
	i = n + 1
	while i <= m:
		moves = None
		if i % 2 == 0:
			moves = 1 + memo[i // 2]
		else:
			moves = 2 + memo[(i + 1) // 2]
		memo[i] = moves
		i = i + 1
	print(memo[m])


(n, m) = [int(x) for x in input().split()]
moves = 0
if n > m:
	print(abs(n - m))
	exit()
while n != m:
	if m % 2 == 0 and m > n:
		m /= 2
		moves += 1
	else:
		m += 1
		moves += 1
print(moves)


(n, m) = (int(x) for x in input().split())
ans = 0
while m > n:
	if m % 2 == 0:
		m //= 2
	else:
		m += 1
	ans += 1
print(ans + n - m)


ch = input()
l = ch.split(' ')
n = int(l[0])
m = int(l[1])
nb = 0
if n > m:
	nb = n - m
else:
	a = n
	i = 0
	while a < m:
		i = i + 1
		a = 2 * a
	j = a - m
	c = 0
	nb = i
	while j >= 2 and c < i:
		nb = nb + j % 2
		j = j // 2
		c = c + 1
	nb = nb + j
print(nb)


import collections
(n, m) = map(int, input().split())
g = [[] for i in range(20002)]
used = [False] * 20002
d = [0] * 20002
g[1].append(2)
for i in range(2, 10001):
	g[i].append(2 * i)
	g[i].append(i - 1)
s = collections.deque()
s.append(n)
while len(s) > 0:
	x = s.popleft()
	for u in g[x]:
		if not used[u]:
			if u < 20003:
				s.append(u)
				d[u] = d[x] + 1
				used[u] = True
			if u == m:
				print(d[m])
				exit()


(n, m) = [int(next) for next in input().split()]
if m <= n:
	print(n - m)
else:
	answer = 0
	while n < m:
		if m % 2 == 1:
			m += 1
			answer += 1
		m //= 2
		answer += 1
	if n == m:
		print(answer)
	else:
		ans = 10000000000
		nn = n
		i = 0
		while nn > 0:
			tmp = i + answer
			while nn < m:
				nn *= 2
				tmp += 1
			tmp += nn - m
			ans = min(ans, tmp)
			i += 1
			nn = n - i
		print(ans)


def two_buttons(start, end):
	cache = get_cache(start)
	temp = start
	while end not in cache:
		cache[temp * 2] = 1 + cache[temp]
		for i in range(temp * 2 - 1, temp, -1):
			if i % 2 == 0:
				cache[i] = 1 + min(cache[i // 2], cache[i + 1])
			else:
				cache[i] = 1 + cache[i + 1]
		temp *= 2
	return cache[end]

def get_cache(start):
	cache = {i: start - i for i in range(1, start)}
	cache[start] = 0
	return cache

def get_points_to_mark(end):
	points_to_mark = [end + 1]
	if end % 2 == 0:
		points_to_mark.append(end // 2)
	return points_to_mark

def points_marked(points_to_mark, cache):
	for point in points_to_mark:
		if point not in cache:
			return False
	return True
(n, m) = [int(e) for e in input().split()]
print(two_buttons(n, m))


from collections import deque
numbers = [int(x) for x in input().split(' ')]
start = int(numbers[0])
end = int(numbers[1])
nums = deque()
nums.append((end, 0))
steps = 0
while len(nums) != 0:
	(current, step) = nums.popleft()
	if current == start:
		print(step)
		break
	elif current % 2 == 0 and current > start:
		nums.append((current / 2, step + 1))
	else:
		nums.append((current + 1, step + 1))


def main() -> object:
	(n, m) = [int(i) for i in input().split()]
	count = 0
	while n < m:
		if m % 2 == 0:
			m >>= 1
		else:
			m += 1
		count += 1
	count += n - m
	return count
print(main())


(n, m) = map(int, input().split())
k = 0
while not m == n:
	if m < n:
		m = m + 1
		k += 1
		continue
	if m % 2 == 0:
		m = m // 2
	else:
		m = m + 1
	k += 1
print(k)


def shortest_path(n, m):
	queue = [n]
	visited = {}
	depth = {n: 0}
	while len(queue) != 0:
		num = queue.pop()
		if num == m:
			return depth[num]
		if num - 1 > 0 and (not visited.get(num - 1, False)):
			queue.insert(0, num - 1)
			visited[num - 1] = True
			depth[num - 1] = depth[num] + 1
		if num < m and (not visited.get(num * 2, False)):
			queue.insert(0, num * 2)
			visited[num * 2] = True
			depth[num * 2] = depth[num] + 1
(n, m) = list(map(lambda s: int(s), input().split(' ')))
print(shortest_path(n, m))


from queue import Queue
a = input().strip().split()
(n, m, ans) = (int(a[0]), int(a[1]), 0)
q = Queue()
q.put((m, 0))
l = [0]
for i in range(30000):
	l.append(int(0))
while not q.empty():
	b = q.get()
	if b[0] == n:
		ans = b[1]
		break
	x = b[0] + 1
	if x > 0 and x < 30000 and (l[x] == 0):
		l[x] = 1
		q.put((x, b[1] + 1))
	if b[0] % 2 == 0:
		x = int(b[0] / 2)
		if x > 0 and x < 30000 and (l[x] == 0):
			l[x] = 1
			q.put((x, b[1] + 1))
print(ans)


(n, m) = map(int, input().split())
s = 0
while n < m:
	s += 1 + m % 2
	m = (m + m % 2) / 2
print(int(s + n - m))


ans = [-1] * 20004

def go(cur):
	ans[cur] = 0
	q = [[cur, 0]]
	while q:
		(u, d) = q.pop(0)
		if u - 1 >= 0:
			if ans[u - 1] == -1:
				ans[u - 1] = d + 1
				q.append([u - 1, d + 1])
		if u * 2 <= 20000:
			if ans[2 * u] == -1:
				ans[2 * u] = d + 1
				q.append([2 * u, d + 1])
(n, m) = map(int, input().split())
go(n)
print(ans[m])


import os
import sys
from io import BytesIO, IOBase
from collections import Counter, defaultdict
from collections import deque
import math

def sin():
	return input()

def ain():
	return list(map(int, sin().split()))

def sain():
	return input().split()

def iin():
	return int(sin())
MAX = float('inf')
MIN = float('-inf')
MOD = 1000000007

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	s = set()
	for p in range(2, n + 1):
		if prime[p]:
			s.add(p)
	return s

def readTree(n, m):
	adj = [deque([]) for _ in range(n + 1)]
	for _ in range(m):
		(u, v) = ain()
		adj[u].append(v)
		adj[v].append(u)
	return adj

def main():
	(n, m) = ain()
	if n >= m:
		print(n - m)
	else:
		Z = 2 * 10 ** 4 + 1
		visited = defaultdict(int)
		q = deque([(n, 0)])
		visited[n] = 1
		while q:
			(num, d) = q.popleft()
			if num == m:
				print(d)
				break
			for child in [num - 1, num * 2]:
				if 0 < child < Z and (not visited[child]):
					visited[child] = 1
					q.append((child, d + 1))
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
if os.getcwd() == 'D:\\code':
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
	input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


def two_degree(n, m):
	deg = 0
	res = n
	while res < m:
		res *= 2
		deg += 1
	print(res)
	return (deg, res - m)
my_str = input()
(n, m) = (int(my_str.split()[0]), int(my_str.split()[1]))
if m < n:
	print(n - m)
else:
	res = n
	oper = 0
	while res != m:
		if m % 2 == 1 and m > res:
			m += 1
			oper += 1
		elif m > res:
			m = int(m / 2)
			oper += 1
		elif m < res:
			oper += res - m
			m = res
	print(oper)


(n, m) = map(int, input().split())
cnt = 0
while True:
	if n == m:
		print(int(cnt))
		break
	if m < n:
		print(int(cnt + n - m))
		break
	elif m % 2 == 0:
		m = m / 2
		cnt += 1
	else:
		m += 1
		cnt += 1


(a, b) = [int(x) for x in input().split()]
count = 0
if b > a:
	while b != a:
		if b < a:
			count += a - int(b)
			b = a
			break
		count += 1
		if b % 2:
			b += 1
		else:
			b = b / 2
	print(count)
else:
	print(a - b)


(n, m) = map(int, input().split())
if n > m:
	print(n - m)
	exit()
ans = 0
while True:
	if m & 1:
		m += 1
		ans += 1
	m //= 2
	ans += 1
	if m <= n:
		break
ans += n - m
print(ans)


def bfs():
	(n, m) = map(int, input().split())
	count = 0
	queue = [[n, count]]
	seen = []
	if n >= m:
		return n - m
	else:
		while queue:
			k = queue.pop()
			xx = k[0]
			t = k[1]
			seen.append(xx)
			if xx == m:
				return t
			else:
				if xx * 2 == m or xx - 1 == m:
					return t + 1
				if xx * 2 not in seen and xx * 2 < m + 11:
					queue = [[xx * 2, t + 1]] + queue
				if xx - 1 not in seen and xx - 1 > 0:
					queue = [[xx - 1, t + 1]] + queue
	return 0
print(bfs())


inp = [int(i) for i in str(input()).split(' ')]
start = inp[0]
ans = inp[1]

def BFS(start, ans):
	if start == ans:
		print(0)
	else:
		SAPairs = [(0, start)]
		explored = {}
		while SAPairs:
			path = SAPairs.pop(0)
			successors = []
			if path[-1] > 0:
				successors.append(path[-1] - 1)
			if path[-1] < ans:
				successors.append(path[-1] * 2)
			counter = path[0] + 1
			for newState in successors:
				if newState not in explored:
					explored[newState] = 1
					if newState == ans:
						return counter
					SAPairs.append((counter, newState))
print(BFS(start, ans))


(n, m) = map(int, input().split())
if m <= n:
	print(n - m)
else:
	l = 0
	x = m
	while x != n:
		if x < n:
			break
		else:
			if x % 2 == 1:
				x += 1
			else:
				x = x // 2
			l += 1
	print(l + n - x)


def f(n, m):
	if n >= m:
		return n - m
	elif m % 2 == 0:
		return f(n, m // 2) + 1
	else:
		return f(n, m // 2 + 1) + 2
(n, m) = list(map(int, input().split()))
print(f(n, m))


(n, m) = map(int, input().split())
INF = 100000000
dp = [INF] * max(n + 2, m + 2)
for i in range(n, 0, -1):
	dp[i] = n - i
for i in range(1, m):
	if 2 * i <= m + 1:
		dp[2 * i] = min(dp[2 * i], dp[i] + 1)
		dp[2 * i - 1] = min(dp[2 * i - 1], dp[i] + 2)
print(dp[m])


import sys

def calculate(n, m):
	if n >= m:
		return n - m
	elif m % 2 == 0:
		return calculate(n, m // 2) + 1
	else:
		return calculate(n, m + 1) + 1
line = list(map(int, sys.stdin.readline().split()))
n = line[0]
m = line[1]
print(calculate(n, m))


import sys
input = lambda : sys.stdin.readline()
int_arr = lambda : list(map(int, input().split()))
str_arr = lambda : list(map(str, input().split()))
get_str = lambda : map(str, input().split())
get_int = lambda : map(int, input().split())
get_flo = lambda : map(float, input().split())
mod = 1000000007

def solve(n, m):
	if n == m:
		print(0)
	else:
		if n > m:
			print(n - m)
			return
		c = 0
		while m > n:
			if m % 2 != 0:
				m += 1
			else:
				m //= 2
			c += 1
		c += n - m
		print(c)
(n, m) = get_int()
solve(n, m)


(begin, want) = map(int, input().split())
diff = want - begin
if diff > 0:
	steps = 0
	while want != begin:
		steps += 1
		if want > begin:
			if want % 2 == 0:
				want = want / 2
			else:
				want += 1
		elif want < begin:
			want += 1
	print(steps)
elif diff < 0:
	print(abs(diff))


3
(n, m) = list(map(int, input().split()))
mem = [2 ** 30] * 4 * max(n, m)
mem[n] = 0
q = [n]
while q:
	c = q.pop(0)
	if 2 * c < len(mem) and mem[2 * c] > mem[c] + 1:
		q.append(2 * c)
		mem[2 * c] = mem[c] + 1
	if c > 1 and mem[c - 1] > mem[c] + 1:
		q.append(c - 1)
		mem[c - 1] = mem[c] + 1
print(mem[m])


(n, m) = input().split()
n = int(n)
m = int(m)
c = 0
while n != m:
	if m > n:
		if m % 2 == 0:
			m = m / 2
			c = c + 1
		else:
			c = c + 1
			m = m + 1
	elif n > m:
		c = c + 1
		m = m + 1
print(c)


import sys
from collections import defaultdict
from functools import lru_cache

def mi(s):
	return map(int, s.strip().split())

def lmi(s):
	return list(mi(s))

def mf(f, s):
	return map(f, s)

def lmf(f, s):
	return list(mf(f, s))
euc_dist = lambda x1, y1, x2, y2: ((x2 - x1) ** 2 + (y2 - y1) ** 2) ** 0.5

def successor(x, y):
	if x - 1 > 0:
		yield (x - 1)
	if x < 2 * y:
		yield (2 * x)

def main(x, y):
	layer = [x]
	visited = set()
	cost = 0
	while layer:
		new_layer = []
		for node in layer:
			visited.add(node)
			if node == y:
				return cost
			for child in successor(node, y):
				if child not in visited:
					new_layer.append(child)
		cost += 1
		layer = new_layer
for (e, line) in enumerate(sys.stdin.readlines()):
	if e == 0:
		(x, y) = mi(line)
print(main(x, y))


from sys import stdin, stdout

def get_value(steps, key, value):
	if key in steps:
		numbers = steps[key]
		numbers.append(value)
		return numbers
	else:
		return [value]

def is_valid(new_number, calculated_numbers):
	max_number = 10000
	if new_number >= 0 and new_number <= max_number and (not new_number in calculated_numbers):
		return True
	return False

def solve(n, m):
	step_count = 0
	calculated_numbers = {}
	steps = {}
	steps[0] = [n]
	max_number = 10000
	while step_count in steps:
		numbers = steps[step_count]
		for number in numbers:
			new_number01 = number - 1
			new_number02 = number * 2
			if new_number01 == m or new_number02 == m:
				return step_count + 1
			if is_valid(new_number01, calculated_numbers):
				value = get_value(steps, step_count + 1, new_number01)
				steps[step_count + 1] = value
			if is_valid(new_number02, calculated_numbers):
				value = get_value(steps, step_count + 1, new_number02)
				steps[step_count + 1] = value
			calculated_numbers[number] = True
		step_count += 1
input_data = [int(x) for x in stdin.readline().rstrip('\r\n').split()]
n = input_data[0]
m = input_data[1]
stdout.write(str(solve(n, m)))


import sys
(a, b) = map(int, input().split())
ans = 0
while a < b:
	if b % 2 != 0:
		b += 1
	else:
		b //= 2
	ans += 1
print(a - b + ans)


def get_count(n, m):
	if m <= n:
		return n - m
	elif m % 2 == 1:
		return 2 + get_count(n, (m + 1) // 2)
	else:
		return 1 + get_count(n, m // 2)
(n, m) = map(int, input().split())
print(get_count(n, m))


(m, n) = map(int, input().split())
t = n
c = 0
if n < m:
	c = m - n
else:
	while t != m:
		if t % 2 == 0 and t > m:
			t = t // 2
			c = c + 1
		else:
			t = t + 1
			c = c + 1
print(c)


from queue import Queue

def bfs(no):
	q = Queue()
	apareceu = set()
	q.put(no)
	apareceu.add(no)
	dist = {no: 0}
	while not q.empty():
		top = q.get()
		for viz in listaAdj[top]:
			if viz not in apareceu:
				apareceu.add(viz)
				dist[viz] = dist[top] + 1
				q.put(viz)
				listaAdj[viz] = []
				e1 = viz * 2
				if e1 not in apareceu and viz <= m:
					listaAdj[viz].append(e1)
				e2 = viz - 1
				if e2 not in apareceu:
					listaAdj[viz].append(e2)
				if e1 == m or e2 == m:
					return dist[viz] + 1
(n, m) = map(int, input().split())
e1 = n * 2
e2 = n - 1
listaAdj = {n: [e1, e2]}
if e1 == m or e2 == m:
	print(1)
else:
	print(bfs(n))


(n, m) = map(int, input().split())
dp = [None] * 10030
todo = [m]
cur = 0
while dp[n] is None:
	newtodo = []
	for x in todo:
		if x < 10030 and dp[x] is None:
			dp[x] = cur
			newtodo.append(x + 1)
			if x % 2 == 0:
				newtodo.append(x // 2)
	cur += 1
	todo = newtodo
print(dp[n])


import sys
ii = lambda : sys.stdin.readline().strip()
idata = lambda : [int(x) for x in ii().split()]
(n, m) = idata()
if n >= m:
	print(n - m)
else:
	(n1, m1) = (n, m)
	count = 0
	while n1 <= m1 // 2:
		if m1 % 2 == 1:
			m1 += 1
			count += 1
		m1 //= 2
		count += 1
	if n1 == m1:
		print(count)
	else:
		print(count + n1 - m1 // 2 + 1)


def Solve(n, m):
	moves = 0
	while True:
		if m < n:
			return moves + n - m
		if m % 2 == 0:
			m = int(m / 2)
		else:
			m += 1
		moves += 1
		if m == n:
			return moves

def main():
	(n, m) = map(int, input().split())
	print(Solve(n, m))
main()


(start, destination) = map(int, input().split())
count = 0
while start != destination:
	if destination < start or destination % 2 != 0:
		destination += 1
	else:
		destination //= 2
	count += 1
print(count)


(n, m) = map(int, input().split())
ans = 0
while 2 * n < m:
	n = 2 * n
	ans += 1
if n < m:
	if m == 2 * n:
		ans += 1
	else:
		n = 2 * n
		ans += 1
		u = ans + 1
		while n != m:
			r = u
			x = 0
			while r > 0 and n > m:
				l = 2 ** x
				if n - l < m:
					l = 2 ** (x - 1)
					n -= l
					break
				if n - l == m or r == 1:
					n = n - l
					break
				x += 1
				r -= 1
			ans += 1
			if n == m:
				break
elif n > m:
	ans = n - m
print(ans)


from math import ceil
counter = 0
(n, m) = [int(x) for x in input().split()]
while m != n:
	if m > n:
		if m % 2 == 0:
			m //= 2
			counter += 1
		else:
			m += 1
			m //= 2
			counter += 2
	else:
		counter += n - m
		m = n
print(counter)


from collections import deque
(n, m) = [int(x) for x in input().split()]

def resp(n, m):
	if n > m:
		return n - m
	else:
		fila = deque([n])
		cont = 0
		visitados = {0: 0, n: n}
		while fila[0] != m:
			v = fila.popleft()
			a = v * 2
			b = v - 1
			if a not in visitados and a <= 2 * m:
				visitados[a] = v
				fila.append(a)
			if b not in visitados and b <= 2 * m:
				visitados[b] = v
				fila.append(b)
		aux = m
		while aux != n:
			aux = visitados[aux]
			cont += 1
		return cont
print(resp(n, m))


(x, y) = map(int, input().split())
q = []
q.append([x, 0])
vis = set()
while q:
	t = q.pop(0)
	if t[0] == y:
		print(t[1])
		break
	if t[0] * 2 == y or t[0] - 1 == y:
		print(t[1] + 1)
		break
	if t[0] * 2 not in vis and t[0] * 2 <= y * 4:
		q.append([t[0] * 2, t[1] + 1])
		vis.add(t[0] * 2)
	if t[0] - 1 >= 0 and t[0] - 1 not in vis:
		q.append([t[0] - 1, t[1] + 1])
		vis.add(t[0] - 1)


from collections import deque
import sys
(n, m) = input().split()
n = int(n)
m = int(m)
numero_cliques = 0
inf = 10002
d = []
for i in range(inf):
	d.append(-1)
Q = deque()
Q.insert(0, n)
d[n] = 0
if m < n:
	print(n - m)
	sys.exit()
while len(Q) != 0:
	top = Q[-1]
	if top == m:
		print(d[top])
	Q.pop()
	if 2 * top <= 10000:
		if d[2 * top] == -1:
			d[2 * top] = d[top] + 1
			Q.insert(0, 2 * top)
	if top > 1 and d[top - 1] == -1:
		d[top - 1] = d[top] + 1
		Q.insert(0, top - 1)


(n, m) = [int(x) for x in input().split()]

def f(init, dest):
	if init >= dest:
		return init - dest
	elif dest % 2 == 1:
		return 1 + f(init, dest + 1)
	else:
		return 1 + f(init, dest / 2)
print(int(f(n, m)))


(n, m) = [int(x) for x in input().split()]
if n >= m:
	print(n - m)
	exit(0)
q = [(n, 0)]
d = {}
while q:
	(v, c) = q.pop(0)
	if v in d:
		continue
	d[v] = True
	if v == m:
		print(c)
		break
	if 2 * v <= 2 * m:
		q.append((2 * v, c + 1))
	if v - 1 > 0:
		q.append((v - 1, c + 1))


import math, sys, re, itertools
(rs, ri, rai) = (input, lambda : int(input()), lambda : list(map(int, input().split())))
(n, m) = rai()
r = 0
while m > n:
	if m % 2 == 1:
		m += 1
		r += 1
	m = m // 2
	r += 1
print(n - m + r)


def test(n, m):
	if n == m:
		return 0
	elif n > m:
		return n - m
	else:
		acc = 0
		if divmod(m, 2)[1] == 1:
			m += 1
			acc += 1
		m = divmod(m, 2)[0]
		return acc + 1 + test(n, m)
(n, m) = (int(i) for i in input().split())
print(test(n, m))


import sys
import random
from math import log2, log, ceil
input = sys.stdin.readline

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)

def primefs(n):
	primes = {}
	while n % 2 == 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	while x != link[x]:
		x = link[x]
	return x

def union(x, y, size, link):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime
MAXN = int(1000000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i

def factoriazation(x):
	ret = {}
	while x != 1:
		ret[spf[x]] = ret.get(spf[x], 0) + 1
		x = x // spf[x]
	return ret

def int_array():
	return list(map(int, input().split()))
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
(n, m) = int_array()
ans = 0
if n >= m:
	print(n - m)
	exit()
if m % 2 != 0:
	m += 1
	ans += 1
while m > n:
	if m % 2 == 0:
		m = m // 2
		ans += 1
	else:
		m += 1
		ans += 1
ans += n - m
print(ans)


def calculate(x, y):
	if x == y:
		return 0
	elif x > y:
		return abs(y - x)
	elif y % 2 == 0:
		return 1 + calculate(x, y // 2)
	else:
		return 1 + calculate(x, y + 1)

def main():
	(show, target) = map(int, input().split())
	print(calculate(show, target))
main()


(n, m) = map(int, input().split())
ans = [-1] * (n + m)
for i in range(1, n + 1):
	ans[i] = n - i
for i in range(n + 1, m + 1):
	if i % 2 == 0:
		ans[i] = 1 + ans[i // 2]
	else:
		ans[i] = 2 + ans[(i + 1) // 2]
print(ans[m])


(n, m) = map(int, input().split())
g = []
for _ in range(1, 20001):
	g.append([])
for i in range(1, 20000):
	g[i].append(i - 1)
for i in range(1, 10001):
	g[i - 1].append(i * 2 - 1)
used = [None] * 20000
used[n - 1] = 0
queue = [n - 1]

def bfs():
	while queue != []:
		for v in g[queue[0]]:
			if used[v] == None:
				queue.append(v)
				used[v] = used[queue[0]] + 1
		del queue[0]
bfs()
print(used[m - 1])


(start, end) = [int(x) for x in input().split()]
times = 0
while True:
	if start == end:
		break
	elif start > end:
		times += start - end
		break
	elif end % 2 == 0:
		end = int(end / 2)
		times += 1
	else:
		end += 1
		times += 1
print(times)


import sys
sys.setrecursionlimit(100000)
(n, m) = map(int, input().split())

def find(stack, m, count=1, visited={}):
	tmp = []
	for e in stack:
		l = e * 2
		r = e - 1
		if l < 2 * m:
			if l not in visited:
				tmp += [l]
				visited[l] = 0
		if r > 0:
			if r not in visited:
				tmp += [r]
				visited[r] = 0
	stack = tmp
	if m in visited:
		return count
	else:
		return find(stack, m, count + 1)
if m < n:
	print(n - m)
else:
	print(find([n], m))


import sys

def read_from_stdin():
	(n, m) = input().split()
	return (int(n), int(m))

def write_to_stdout(res):
	sys.stdout.write('%d\n' % res)

def half_the_number(number, n):
	count = 0
	while number % 2 == 0 and number > n:
		new_number = number / 2
		if int(new_number) * 2 == number:
			number = int(new_number)
			count += 1
		else:
			break
	return (number, count)

def get_answer(n, m):
	res = n
	count = 0
	while m != n:
		if m % 2 == 0:
			(m, count_half) = half_the_number(m, n)
			count += count_half
			if m < n:
				count += n - m
				break
		else:
			m += 1
			count += 1
	return count

def main():
	(n, m) = read_from_stdin()
	res = get_answer(n, m)
	write_to_stdout(res)
main()


import sys
range = sys.stdin.readline()
range_list = range.split()
range1 = int(range_list[0])
range2 = int(range_list[1])
count = 0
if range2 > range1:
	while range2 > range1:
		if range2 % 2 == 0:
			range2 /= 2
		else:
			range2 += 1
		count += 1
	count += range1 - range2
else:
	count = range1 - range2
print(int(count))


T_ON = 0
DEBUG_ON = 1
MOD = 998244353

def solve():
	(n, m) = read_ints()
	if m <= n:
		print(n - m)
		return
	cnt = 0
	while m > n:
		if m % 2:
			m = m + 1
		else:
			m = m // 2
		cnt += 1
	cnt += n - m
	print(cnt)

def main():
	T = read_int() if T_ON else 1
	for i in range(T):
		solve()

def dbg(*xargs):
	if DEBUG_ON:
		print(*xargs)
from collections import *
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def read_int():
	return int(input())

def read_ints():
	return list(map(int, input().split()))

def print_nums(nums):
	print(' '.join(map(str, nums)))

def YES():
	print('YES')

def Yes():
	print('Yes')

def NO():
	print('NO')

def No():
	print('No')

def fib(n):
	(a, b) = (0, 1)
	for _ in range(n):
		(a, b) = (b, a + b)
	return a

def fib_ns(n):
	assert n >= 1
	f = [0 for _ in range(n + 1)]
	f[0] = 0
	f[1] = 1
	for i in range(2, n + 1):
		f[i] = f[i - 1] + f[i - 2]
	return f

def gcd(a, b):
	if a == 0:
		return b
	return gcd(b, a % b)

def xgcd(a, b):
	(x0, x1, y0, y1) = (0, 1, 1, 0)
	while a != 0:
		((q, a), b) = (divmod(b, a), a)
		(y0, y1) = (y1, y0 - q * y1)
		(x0, x1) = (x1, x0 - q * x1)
	return (b, x0, y0)

def modinv(a, m):
	(g, x, _) = xgcd(a, m)
	if g != 1:
		raise Exception('gcd(a, m) != 1')
	return x % m

def mod_add(x, y):
	x += y
	while x >= MOD:
		x -= MOD
	while x < 0:
		x += MOD
	return x

def mod_mul(x, y):
	return x * y % MOD

def mod_pow(x, y):
	if y == 0:
		return 1
	if y % 2:
		return mod_mul(x, mod_pow(x, y - 1))
	p = mod_pow(x, y // 2)
	return mod_mul(p, p)

def mod_inv(y):
	return mod_pow(y, MOD - 2)

def mod_div(x, y):
	return mod_mul(x, mod_inv(y))

def is_prime(n):
	if n == 1:
		return False
	for i in range(2, int(n ** 0.5) + 1):
		if n % i:
			return False
	return True

def gen_primes(n):
	P = [True for _ in range(n + 1)]
	P[0] = P[1] = False
	for i in range(int(n ** 0.5) + 1):
		if P[i]:
			for j in range(2 * i, n + 1, i):
				P[j] = False
	return P
main()


def solve():
	(n, m) = map(int, input().split())
	count = 0
	while n != m:
		count += 1
		if m < n:
			m += 1
		elif m % 2 == 0:
			m /= 2
		else:
			m += 1
	print(count)
solve()


def foo(n, m):
	if n >= m:
		return n - m
	elif m % 2 == 0:
		return 1 + foo(n, m / 2)
	else:
		return 1 + foo(n, m + 1)
(n, m) = map(int, input().strip().split())
print(int(foo(n, m)))


def getPushes(n, m):
	pushes = 0
	while m != n:
		if m < n:
			m += 1
		elif m % 2 == 0:
			m /= 2
		else:
			m += 1
		pushes += 1
	return pushes
s = input().split()
n = int(s[0])
m = int(s[1])
if m <= n:
	print(n - m)
else:
	print(int(getPushes(n, m)))


import heapq as hp
import collections

def unpack(func=int):
	return map(func, input().split())

def l_unpack(func=int):
	return list(map(func, input().split()))

def s_unpack(func=int):
	return sorted(map(func, input().split()))

def range_n():
	return range(int(input()))

class Graph:

	def __init__(self, v):
		self.graph = [None] * (v + 1)
		self.size = v

	def addedge(self, u, v):
		if self.graph[u]:
			self.graph[u].add(v)
		else:
			self.graph[u] = {v}

	def shortestpath(self, u, v):
		deq = collections.deque()
		deq.append(u)
		ans = [-1] * (self.size + 1)
		ans[u] = 0
		while deq:
			curr = deq.popleft()
			if self.graph[curr]:
				for node in self.graph[curr]:
					if node < self.size and ans[node] == -1:
						ans[node] = ans[curr] + 1
						deq.append(node)
		return ans

def main():
	(n, m) = unpack()
	if n >= m:
		print(n - m)
	else:
		graph = Graph(2 * m)
		for i in range(1, 2 * m + 1):
			graph.addedge(i, 2 * i)
			graph.addedge(i, i - 1)
		bfs = graph.shortestpath(n, m)
		print(bfs[m])
main()


(n, m) = list(map(int, input().split()))
l = 0
if m == n:
	print('0')
elif m < n:
	print(n - m)
else:
	while m > n:
		if m % 2 == 0:
			l += 1
			m /= 2
		else:
			l += 1
			m += 1
	print(int(l + n - m))


input = input().split(' ')
n = int(input[0])
m = int(input[1])
result = 0
while n < m:
	if m % 2 == 0:
		m //= 2
	else:
		m += 1
	result += 1
if n > m:
	result += n - m
print(result)


import math
(n, m) = map(int, input().split())
cnt = 0
while n < m:
	if m % 2 == 0:
		m //= 2
	else:
		m += 1
	cnt += 1
cnt += n - m
print(cnt)


import queue
dicio = {}
q = queue.Queue()

def bfs(x, y):
	q.put(x)
	dicio[x] = 0
	while q.empty() == False:
		r = q.get(x)
		if r < 0 or r > 2 * 10 ** 4:
			continue
		a = r - 1
		b = r * 2
		if r == y:
			return dicio[r]
		if a not in dicio:
			dicio[a] = dicio[r] + 1
			q.put(a)
		if b not in dicio:
			dicio[b] = dicio[r] + 1
			q.put(b)
(x, y) = map(int, input().split())
print(bfs(x, y))


import math
(n, m) = [int(s) for s in input().rstrip().split(' ')]
mids = [m]
while mids[-1] > n:
	mids.append(math.ceil(mids[-1] / 2))
p = 0
while len(mids) > 0:
	p += n - mids[-1] + 1
	n = mids.pop() * 2
print(p - 1)


vhod = input()
vhod_list = vhod.split()
do = int(vhod_list[0])
posle = int(vhod_list[1])
kostilist = []
uroven = 0
fixprice = 0
maxuroven = 0
fixkostil = 0
shagi = 0

def search(do):
	global kostilist
	it = 0
	while do < kostilist[it]:
		it += 1
	if do == kostilist[it]:
		return do
	if it == 0:
		return kostilist[0]
	if do - kostilist[it] < do * 2 - kostilist[it]:
		return kostilist[it]
	else:
		return kostilist[it - 1]

def recc(do, posle, kostilist):
	it = 0
	global shagi
	while do != kostilist[it]:
		it += 1
	if it == 0:
		return -1
	while do != posle:
		if it > 0:
			if do * 2 == kostilist[it - 1]:
				shagi += 1
				do *= 2
				it -= 1
			else:
				shagi += 2
				do *= 2
				do -= 1
				it -= 1
		if it == 0:
			if do * 2 == posle:
				shagi += 1
				do = do * 2
			else:
				shagi += 2
				do = do * 2 - 1
	return do

def rekursivnoelezhat(do, posle):
	global kostilist
	global shagi
	fixprice = 0
	while do != posle:
		fixprice = search(do)
		if fixprice < do:
			while do != fixprice:
				do -= 1
				shagi += 1
		elif fixprice == do:
			if fixprice == kostilist[0]:
				shagi += 1
				do *= 2
		else:
			do *= 2
			shagi += 1
			while do != fixprice:
				do -= 1
				shagi += 1
		if do == posle:
			return
		kostil = recc(do, posle, kostilist)
		if kostil == -1:
			shagi += 1
			do *= 2
			if do == posle + 1:
				shagi += 1
				return
		elif kostil == posle:
			return
		else:
			do = kostil
			shagi += 1
			do *= 2

def lezhat(do, posle):
	global kostilist
	global shagi
	novoeposle_1 = 0
	if posle % 2 == 0:
		novoeposle_1 = posle
		while novoeposle_1 != 1:
			kostilist.append(int(novoeposle_1 / 2))
			novoeposle_1 /= 2
			if novoeposle_1 == 1:
				break
			if novoeposle_1 % 2 != 0:
				novoeposle_1 += 1
	else:
		novoeposle_1 = posle + 1
		while novoeposle_1 != 1:
			kostilist.append(int(novoeposle_1 / 2))
			novoeposle_1 /= 2
			if novoeposle_1 == 1:
				break
			if novoeposle_1 % 2 != 0:
				novoeposle_1 += 1
	it = 0
	if do > posle:
		while do > posle:
			do -= 1
			it += 1
		print(it)
	elif do == posle:
		print(0)
	else:
		rekursivnoelezhat(do, posle)
		print(shagi)
lezhat(do, posle)


def fun(n, m):
	if n >= m:
		return n - m
	Q = [n]
	mySet = set()
	cnt = 1
	while True:
		new_Q = []
		for num in Q:
			x = 2 * num
			y = num - 1
			if x == m or y == m:
				return cnt
			if not x in mySet and x < 20000 and (x > 0):
				mySet.add(x)
				new_Q.append(x)
			if not y in mySet and y < 20000 and (y > 0):
				mySet.add(y)
				new_Q.append(y)
		Q = new_Q
		cnt += 1
(n, m) = [int(c) for c in input().split()]
print(fun(n, m))


(x, y) = [int(a) for a in input().split()]
z = 0
if y < x:
	print(x - y)
	quit()
else:
	while y > x:
		if y % 2 == 0:
			y = y / 2
			z += 1
		else:
			y += 1
			z += 1
print(int(abs(z + x - y)))


(n, m) = map(int, input().split())
if n >= m:
	print(n - m)
else:
	count = 0
	while m > n:
		if m % 2 == 0:
			m //= 2
			count += 1
		else:
			count += 1
			m += 1
	if m == n:
		print(count)
	else:
		c1 = count + (n - m)
		while m != n:
			if m % 2 == 0:
				m //= 2
				count += 1
			else:
				count += 1
				m += 1
			if count > c1:
				break
		print(min(c1, count))


from collections import deque
(a, b) = map(int, input().split(' '))
pre = {}
fila = deque([a])
cont = 0
while fila:
	v = fila.popleft()
	if 2 * v not in pre and 2 * v < b * 2:
		fila.append(2 * v)
		pre[2 * v] = v
		if v * 2 == b:
			break
	if v - 1 not in pre:
		fila.append(v - 1)
		pre[v - 1] = v
		if v - 1 == b:
			break
x = b
while x != a:
	x = pre[x]
	cont += 1
print(cont)


currentsteps = 9999999999999

def step(current, goal, steps, stepes):
	global currentsteps
	if stepes > 500:
		return 99999999999999
	if steps > currentsteps:
		return steps
	valores = []
	for n in current:
		if n >= goal:
			val = steps + abs(n - goal)
			if val < currentsteps:
				currentsteps = val
			continue
		elif n >= goal / 2:
			val = abs(n - int(goal / 2)) + 1
			if val < currentsteps:
				currentsteps = val
			continue
		if n < goal:
			valor1 = n * 2
			if valor1 == goal:
				return steps + 1
			if valor1 not in valores:
				valores.append(valor1)
		if n >= goal / 2:
			valor2 = n - 1
			if valor2 == goal:
				return steps + 1
			if valor2 >= 0 and valor2 not in valores:
				valores.append(valor2)
	if len(valores) == 0:
		return 9999999999
	else:
		return step(valores, goal, steps + 1, stepes + 1)
line = input()
numbers = line.split(' ')
n = int(numbers[0])
m = int(numbers[1])
goal = m
divnumber = 0
impares = []
while n < goal / 2 and goal % 2 == 0 or (n < int(goal / 2 + 1) and goal % 2 == 1):
	divnumber += 1
	if goal % 2 == 0:
		goal = int(goal / 2)
		impares.append(False)
	else:
		goal = int(goal / 2 + 1)
		impares.append(True)
launch = n
min = step([launch], goal, 0, 0)
if currentsteps <= min:
	min = currentsteps
for i in range(0, divnumber):
	launch = goal
	if impares[-1 - i] == True:
		goal -= 1
		goal *= 2
		goal += 1
	else:
		goal *= 2
	currentsteps = 99999999999989
	newmin = step([launch], goal, 0, 0)
	if currentsteps <= newmin:
		newmin = currentsteps
	min += newmin
print(min)


(a, b) = input().split()
(a, b) = (int(a), int(b))
ct = 0
while b > a:
	if b % 2 != 0:
		b += 1
	else:
		b = b // 2
	ct += 1
ct += a - b
print(ct)


import queue
(n, m) = map(int, input().split())
if m < n:
	print(n - m)
else:
	visited = [0 for _ in range(10001)]
	distance = [0 for _ in range(10001)]
	q = []
	q.append(n)
	distance[n] = 0
	visited[n] = 1
	while q[0] != m:
		u = q[0]
		q.remove(u)
		if u != 0:
			if visited[u - 1] == 0:
				distance[u - 1] = distance[u] + 1
				visited[u - 1] = 1
				q.append(u - 1)
		if u < m and u * 2 < 10001:
			if visited[u * 2] == 0:
				distance[u * 2] = distance[u] + 1
				q.append(u * 2)
				visited[u * 2] = 1
	print(distance[m])


(n, m) = (int(x) for x in input().split())

def buttons(n, m):
	if n >= m:
		return n - m
	if m % 2 == 0:
		return 1 + buttons(n, m // 2)
	else:
		return 1 + buttons(n, m + 1)
print(buttons(n, m))


(a, b) = map(int, input().split())
c = 0
while a != b:
	if a > b:
		c += a - b
		a = b
	elif b % 2:
		b = (b + 1) // 2
		c += 2
	else:
		b //= 2
		c += 1
print(c)


from collections import defaultdict

def bfs(start, end):
	seen = set()
	steps = defaultdict()
	neighbors = [start]
	steps[start] = 0
	while neighbors:
		current = neighbors.pop(0)
		if current == end:
			return steps[current]
		elif current < 0:
			continue
		elif current not in seen:
			seen.add(current)
			neighbors.append(current - 1)
			steps[current - 1] = steps[current] + 1
			if current < end:
				neighbors.append(current * 2)
				steps[current * 2] = steps[current] + 1
	return -1
(n, m) = map(int, input().split())
if m < n:
	print(n - m)
else:
	print(bfs(n, m))


import sys

class Linear_Graph:

	def __init__(self, lis):
		self._vertices = lis
		self._connections = dict()

	def construct_links(self):
		for vert in self._vertices:
			if vert not in self._connections:
				self._connections[vert] = []
				if vert - 1 in self._vertices:
					self._connections[vert].append(vert - 1)
				if vert * 2 in self._vertices:
					self._connections[vert].append(vert * 2)

	def print(self):
		print(self._connections)

	def shortest_path(self, start, end, discovered):
		level = [start]
		discovered[start] = None
		depth = 0
		while len(level) > 0:
			next_level = []
			for vert in level:
				for adjacent in self._connections[vert]:
					if adjacent == end:
						depth += 1
						print(depth)
						sys.exit()
					if adjacent not in discovered:
						next_level.append(adjacent)
						discovered[adjacent] = vert
			level = next_level
			depth += 1
(start, end) = map(int, input().split())
if start >= end:
	print(start - end)
	sys.exit()
a = Linear_Graph(list(range(1, end * 2 + 10)))
a.construct_links()
print(a.shortest_path(start, end, dict()))


(n, m) = [int(x) for x in input().split()]
flag = True
c = 0
while flag:
	if m < n:
		print(n - m + c)
		break
	elif m % 2 == 0:
		m //= 2
		c += 1
	else:
		m += 1
		c += 1
	if m == n:
		flag = False
		print(c)


nums = [int(x) for x in input().split(' ')]
n = nums[0]
m = nums[1]
if n > m:
	print(n - m)
else:
	count = 0
	while m != n:
		if m > n:
			if m % 2 == 0:
				m /= 2
			else:
				m += 1
		else:
			m += 1
		count += 1
	print(count)


from sys import stdin

def test_case(n, m):
	s = set()
	s.add(n)
	q = [(n, 0)]
	while q:
		(u, w) = q.pop(0)
		if u == m:
			print(w)
			return True
		if u < m:
			r = u * 2
			if r not in s:
				s.add(r)
				q.append((r, w + 1))
		if u > 0:
			b = u - 1
			if b not in s:
				s.add(b)
				q.append((b, w + 1))
	return False

def main():
	for s in stdin:
		test_case(*(int(v) for v in s.split()))
main()


def get_step(n, m):
	step = 0
	while m > n:
		if m % 2 == 0:
			m //= 2
		else:
			m += 1
		step += 1
	if m == n:
		return step
	else:
		return step + n - m
(n, m) = input().split(' ')
n = int(n)
m = int(m)
print(get_step(n, m))


from collections import deque

def get_reachable_nodes(N, M):
	visited = set([N])
	to_visit = deque([(N, 0)])
	while to_visit:
		(node, length) = to_visit.popleft()
		if node == M:
			return length
		(s, m) = (node - 1, node * 2)
		if not s in visited and s > 0:
			to_visit.append((s, length + 1))
			visited.add(s)
		if not m in visited and node < M:
			to_visit.append((m, length + 1))
			visited.add(m)
	return -1
(N, M) = tuple(map(int, input().split()))
print(get_reachable_nodes(N, M))


(n, m) = map(int, input().split())
a = 0
while n != m:
	if m > n:
		if m % 2 == 0:
			m /= 2
			a += 1
		else:
			m += 1
			a += 1
	elif n > m:
		m += 1
		a += 1
print(abs(a))


from heapq import *
__author__ = 'artyom'

def neighbours(vertex, limit):
	res = []
	if vertex > 1:
		res.append(vertex - 1)
	if vertex < limit:
		res.append(vertex * 2)
	return res

def dijkstra(source, target):
	(q, seen) = ([(0, source, ())], set())
	while q:
		(cost, v1, path) = heappop(q)
		if v1 not in seen:
			seen.add(v1)
			path = (v1, path)
			if v1 == target:
				return cost
			for v2 in neighbours(v1, target):
				if v2 not in seen:
					heappush(q, (cost + 1, v2, path))
	return float('inf')
(n, m) = map(int, input().split())
print(n - m if n >= m else dijkstra(n, m))


from sys import stdin
input = stdin.readline().rstrip()
(n, m) = (int(input.split()[0]), int(input.split()[1]))
q = [n]
visited = {}
count = {n: 0}
while q:
	num = q.pop()
	if num == m:
		print(count[num])
		break
	if num - 1 > 0 and (not visited.get(num - 1)):
		q.insert(0, num - 1)
		visited[num - 1] = True
		count[num - 1] = count[num] + 1
	if num < m and (not visited.get(num * 2)):
		q.insert(0, num * 2)
		visited[num * 2] = True
		count[num * 2] = count[num] + 1


from queue import *
q = Queue()
line = input().split()
start = int(line[0])
end = int(line[1])
q.put(start)
q.put(0)
a = set()
a.add(start)
while q.empty() == False:
	x = q.get()
	steps = q.get()
	if x == end:
		print(steps)
		break
	if 20000 > 2 * x and 2 * x not in a:
		q.put(2 * x)
		q.put(steps + 1)
		a.add(2 * x)
	if x - 1 >= 0 and x - 1 not in a:
		q.put(x - 1)
		q.put(steps + 1)
		a.add(x - 1)


(n, m) = map(int, input().split())
times = 0
while n != m:
	if n > m or m % 2 != 0:
		m += 1
		times += 1
	elif m % 2 == 0:
		m /= 2
		times += 1
print(times)


(n, m) = list(map(int, input().strip().split()))
c = m - n
for i in range(1000):
	if m <= n:
		break
	if m % 2 != 0:
		m = m + 1
		continue
	else:
		m = m / 2
		continue
print([int(i + n - m), -c][c <= 0])


a = list(map(int, input().split()))
start = a[1]
end = a[0]
answer = 0
while end != start:
	if start < end:
		answer += end - start
		break
	if start % 2 == 0:
		start //= 2
	else:
		start += 1
	answer += 1
print(answer)


from collections import deque
(n, m) = map(int, input().split())
graph = {}
graph[n] = [n - 1, n * 2]
queue = deque()
queue += [n]
searched = {}
k = [1]
i = 1
s = 0

def check_number(a):
	if a == m:
		return True
	if a > m:
		graph[a] = [a - 1]
	if a < m:
		graph[a] = [a - 1, 2 * a]
	searched[a] = 1
	return False
while queue:
	a = queue.popleft()
	i -= 1
	if a < 0:
		pass
	elif a not in searched:
		if check_number(a):
			print(len(k) - 1)
			break
		else:
			queue += graph[a]
			s += len(graph[a])
	if i == 0:
		i = s
		k.append(s)
		s = 0


numbers = input()
number_array = numbers.split(' ')
first_num = int(number_array[0])
second_num = int(number_array[1])
steps = 0
if first_num != second_num:
	while second_num > first_num:
		if second_num % 2 == 1:
			steps += 1
			second_num += 1
		second_num /= 2
		steps += 1
	if second_num != first_num:
		steps += int(first_num - second_num)
print(steps)


from queue import Queue

def bfs(x, y):
	if x == y:
		return 0
	dicionario = {}
	visitas = [False] * 10010
	fila = Queue()
	fila.put(x)
	visitas[x] = True
	dicionario[x] = 0
	while True:
		t = fila.get()
		if t == y:
			return dicionario[t]
		ba = t - 1
		bv = t * 2
		if 0 < bv < 10010 and (not visitas[bv]):
			dicionario[bv] = dicionario[t] + 1
			visitas[bv] = True
			fila.put(bv)
		if 0 < ba < 10010 and (not visitas[ba]):
			dicionario[ba] = dicionario[t] + 1
			visitas[ba] = True
			fila.put(ba)
(x, y) = map(int, input().split())
print(bfs(x, y))


import os
import re
import sys
from bisect import bisect, bisect_left, insort, insort_left
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from io import BytesIO, IOBase
from itertools import accumulate, combinations, combinations_with_replacement, groupby, permutations, product
from math import acos, asin, atan, ceil, cos, degrees, factorial, hypot, log2, pi, radians, sin, sqrt, tan
from operator import itemgetter, mul
from string import ascii_lowercase, ascii_uppercase, digits

def inp():
	return int(input())

def inlist():
	return list(map(int, input().split()))

def instr():
	s = input()
	return list(s[:len(s)])

def invr():
	return map(int, input().split())

def bfs(n, m, a):
	visited = [0] * 100001
	dist = [0] * 100001
	Q = []
	Q.append(n)
	visited[n] = 1
	while len(Q) > 0 and visited[m] == False:
		u = Q.pop(0)
		for v in a[u]:
			if visited[v] == False:
				visited[v] = True
				Q.append(v)
				dist[v] = dist[u] + 1
	return dist[m]

def main():
	(n, m) = invr()
	a = defaultdict(lambda : [])
	l = 100001
	mark = [0] * l
	for i in range(1, l):
		if mark[i] == 0:
			mark[i] = 1
			prev = i
			j = i * 2
			while j < l:
				mark[j] = 1
				a[prev].append(j)
				a[prev].append(prev - 1)
				prev = j
				j *= 2
	res = bfs(n, m, a)
	print(res)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')
main()


(n, m) = map(int, input().split())
if m <= n:
	print(n - m)
else:
	for i in range(1, m // n + 2):
		if n * 2 ** i >= m:
			a = i
			break
	if n * 2 ** a == m:
		print(a)
	else:
		ncount = 1
		while n != m:
			if n > m / 2 ** a > n - 1:
				n *= 2
				ncount += 1
				a -= 1
				b = 0
			elif n - 1 > m / 2 ** a:
				n -= 1
				ncount += 1
				b = 0
			else:
				b = 1
				break
		if b == 0:
			print(ncount)
		else:
			print(ncount + a)


import queue
nums = [int(x) for x in input().split(' ')]
if nums[0] > nums[1]:
	print(nums[0] - nums[1])
else:
	q = queue.Queue()
	visit = set()
	q.put((nums[0], 0))
	while not q.empty():
		n = q.get()
		if n[0] == nums[1]:
			print(n[1])
			break
		visit.add(n[0])
		if n[0] * 2 == nums[1] or n[0] - 1 == nums[1]:
			print(n[1] + 1)
			break
		if n[0] < nums[1] and n[0] * 2 not in visit:
			q.put((n[0] * 2, n[1] + 1))
		if n[0] - 1 >= 0 and n[0] - 1 not in visit:
			q.put((n[0] - 1, n[1] + 1))


R = lambda : map(int, input().split())
(n, m) = R()
if m <= n:
	print(n - m)
else:
	res = 0
	while n != m:
		res += 1
		if m < n or m & 1:
			m += 1
		else:
			m //= 2
	print(res)


f = lambda : input()
(n, m) = list(map(int, f().split()))
dp = [99999] * 10001
dp[n] = 0

def click():
	for i in range(0, n + 1):
		dp[i] = n - i
		if i * 2 <= 10000:
			if dp[i * 2] > dp[i] + 1:
				dp[i * 2] = dp[i] + 1
	for i in range(n + 1, 10001):
		if dp[i] == 99999:
			d = 1
			while i + d <= 10000 and dp[i + d] == 99999:
				d += 1
			if i + d <= 10000:
				dp[i] = d + dp[i + d]
		if i * 2 <= 10000 and dp[i * 2] > dp[i] + 1:
			dp[i * 2] = dp[i] + 1
click()
print(dp[m])


import sys
numbers = sys.stdin.readline().split(' ')
numbers = list(map(int, numbers))
p = numbers[0]
q = numbers[1]
count2 = 0
count1 = 0
while q > p:
	if q % 2 != 0:
		q = (q + 1) / 2
		count2 = count2 + 1
		count1 = count1 + 1
	elif q % 2 == 0:
		q = q / 2
		count2 = count2 + 1
diff = p - q
ans = count2 + count1 + diff
print(int(ans))


(n, m) = [int(x) for x in input().split(' ')]
import math
x = math.log(m / n, 2)

def f(x):
	if x < 0:
		return 0
	else:
		return math.ceil(x)
y = 2 ** f(x)
a = n * y - m
b = f(x) + int(a / y) + bin(a % y).count('1')
print(b)


(n, m) = [int(i) for i in input().split()]
result = 0
while m > n:
	if m % 2 == 0:
		m = m // 2
		result += 1
	else:
		m = (m + 1) // 2
		result += 2
result += n - m
print(result)


from sys import stdin, stdout
import time
from collections import defaultdict
mxN = 2 * 10000
depth = [float('inf') for i in range(mxN + 1)]

def solve(n, m):
	if n == m:
		return 0
	cnt = 0
	q = [n]
	ans = float('inf')
	depth[n] = 0
	while q:
		a = q.pop(0)
		if a * 2 == m:
			ans = depth[a] + 1
			break
		if a - 1 == m:
			ans = depth[a] + 1
			break
		if a != 0:
			if a > m:
				ans = depth[a] + a - m
				continue
			else:
				q.append(a * 2)
				q.append(a - 1)
				depth[a * 2] = min(depth[a * 2], depth[a] + 1)
				depth[a - 1] = min(depth[a - 1], depth[a] + 1)
	return ans
(N, M) = map(int, stdin.readline().split())
c = 0
while N != M:
	c += 1
	if M & 1 or M < N:
		M += 1
	else:
		M = M // 2
print(c)


from math import inf
(n, m) = map(int, input().split(' '))
if n > m:
	print(n - m)
else:
	s = n - 1
	visited = [False for i in range(2 * m)]
	dist = [inf for i in range(2 * m)]
	q = [s]
	dist[s] = 0
	visited[s] = True
	while q:
		idx = q.pop(0)
		a = idx - 1
		b = 2 * idx + 1
		if a >= 0:
			if visited[a] == False:
				dist[a] = dist[idx] + 1
				visited[a] = True
				q.append(a)
		if b < 2 * m:
			if visited[b] == False:
				dist[b] = dist[idx] + 1
				visited[b] = True
				q.append(b)
		if a == m - 1:
			break
		if b == m - 1:
			break
	print(dist[m - 1])


(n, m) = list(map(int, input().split()))
if m < n:
	print(n - m)
else:
	t = 0
	while True:
		if m <= n:
			t += n - m
			break
		if m % 2 == 0:
			m //= 2
		else:
			m += 1
		t += 1
	print(t)


def two_buttons(start, end):
	cache = get_cache(start)
	temp = start + 1
	while end not in cache:
		if temp % 2 == 0:
			cache[temp] = 1 + cache[temp / 2]
		else:
			cache[temp] = 2 + cache[(temp + 1) / 2]
		temp += 1
	return cache[end]

def get_cache(start):
	cache = {i: start - i for i in range(1, start)}
	cache[start] = 0
	return cache
(n, m) = [int(e) for e in input().split()]
print(two_buttons(n, m))


(n, t) = map(int, input().split(' '))
if t <= n:
	print(abs(t - n))
else:
	count = 0
	if t % 2 != 0:
		count += 1
		t += 1
	while t > n:
		t = t / 2
		count += 1
		if t % 2 != 0 and t != n:
			count += 1
			t += 1
	count += n - t
	print(int(count))


from math import inf
(n, m) = map(int, input().split())
steps = [inf for i in range(20001)]
bfs_queue = [n]
steps[n] = 0
while steps[m] == inf:
	current = bfs_queue.pop(0)
	neighbors = []
	if current >= 2:
		neighbors.append(current - 1)
	if current * 2 <= 20000:
		neighbors.append(current * 2)
	for i in neighbors:
		if steps[i] == inf:
			steps[i] = steps[current] + 1
			bfs_queue.append(i)
print(str(steps[m]))


(n, p) = map(int, input().split())

def dp(n, p, steps=0):
	if n >= p:
		return steps + n - p
	steps += 1
	x = p // 2
	if p % 2:
		steps += 2 * (p // 2 + 1) - p
		x += 1
	return dp(n, x, steps)
print(dp(n, p))


from collections import defaultdict
from collections import deque

def BFS(d, n, m, visited):
	queue = deque([(0, n)])
	while len(queue):
		(level, temp) = queue.popleft()
		if temp == m:
			return level
		visited[temp] = 1
		for i in d[temp]:
			if i > len(visited) - 1:
				continue
			if visited[i] == 0:
				queue.append((level + 1, i))
visited = [0 for i in range(1, 2 * 10 ** 4 + 1)]
d = defaultdict(list)
for i in range(1, 2 * 10 ** 4 + 1):
	if i - 1 > 0:
		d[i].append(i - 1)
	d[i].append(2 * i)
(n, m) = map(int, input().split())
print(BFS(d, n, m, visited))


import heapq

def main():
	(n, m) = map(int, input().split())
	stack = [(0, n)]
	ans = 0
	while n < m:
		if m % 2 == 0:
			m = m // 2
		else:
			m += 1
		ans += 1
	ans += n - m
	print(ans)
main()


(start, end) = map(int, input().split())
count = 0
while end > start:
	if end % 2 == 0:
		end = end / 2
		count += 1
	else:
		end = (end + 1) / 2
		count += 2
print(int(count + abs(start - end)))


(n, m) = map(int, input().split())
distance = [-1] * 10000001
distance[n] = 0
q = [n]
while len(q) > 0:
	u = q.pop(0)
	v = u * 2
	x = u - 1
	if distance[v] == -1 and v < m * 2:
		distance[v] = distance[u] + 1
		q.append(v)
	if distance[x] == -1 and x > 0:
		distance[x] = distance[u] + 1
		q.append(x)
print(distance[m])


def rec(n, m):
	if m == n:
		return 0
	elif (m + 1) // 2 < n:
		return n - m // 2 + 1
	elif (m + 1) // 2 >= n:
		if m % 2 == 0:
			return 1 + rec(n, m // 2)
		else:
			return 1 + 1 + rec(n, (m + 1) // 2)

def main():
	s = input().split()
	n = int(s[0])
	m = int(s[1])
	if n > m:
		print(n - m)
	elif n <= m:
		print(rec(n, m))
main()


def twoButtons(n, m):
	cuenta = 0
	if n > m:
		return n - m
	while n < m:
		if m % 2 == 0:
			m //= 2
		else:
			m += 1
		cuenta += 1
	return abs(cuenta + n - m)
a = list(map(int, input().split()))
print(twoButtons(a[0], a[1]))


def minimum_push(n, m):
	if n >= m:
		return n - m
	if m % 2 == 0:
		return 1 + minimum_push(n, m // 2)
	else:
		return 1 + minimum_push(n, m + 1)
(n, m) = map(int, input().split())
print(minimum_push(n, m))


def best_value(value):
	if value % 2 == 0:
		return int(value / 2)
	else:
		return value + 1
(n, m) = [int(x) for x in input().split()]
if n >= m:
	print(n - m)
else:
	bestShot = m
	count = 0
	while bestShot > n:
		bestShot = best_value(bestShot)
		count += 1
	count += n - bestShot
	print(count)


nums = list(map(int, input().split()))
n = nums[0]
m = nums[1]
count = 0
while m != n:
	if m > n and m % 2 == 0:
		m /= 2
	else:
		m += 1
	count += 1
print(count)


def twoBotton(n, m):
	q = [(n, 0)]
	visited = set()
	while q:
		(cur, count) = q.pop(0)
		if cur == m:
			return count
		if cur * 2 < m * 2 and cur * 2 not in visited:
			visited.add(cur * 2)
			q.append((cur * 2, count + 1))
		if cur - 1 >= 0 and cur - 1 not in visited:
			visited.add(cur - 1)
			q.append((cur - 1, count + 1))
	return -1
(x, y) = input().split()
print(twoBotton(int(x), int(y)))


from collections import deque

def bfs(graph, visited, start, goal):
	path = 0
	q = deque()
	q.append((start, 0))
	while len(q) > 0:
		(node, level) = q.popleft()
		if node == goal:
			return level
		if node < len(graph):
			visited[node] = True
			for edge in graph[node]:
				if edge < len(graph) and (not visited[edge]):
					q.append((edge, level + 1))
(n, m) = map(int, input().split())
x = max(n, m)
graph = [[] for i in range(x * 2)]
visited = [False for i in graph]
for (i, edges) in enumerate(graph):
	if i == 0:
		continue
	if i == 1:
		edges.append(2)
	else:
		edges.append(i - 1)
		edges.append(i * 2)
print(bfs(graph, visited, n, m))


(n, m) = list(map(lambda x: int(x), input().split()))
graph = {}
for i in range(2, 10 ** 4 + 1):
	graph[i] = []
graph[1] = [2]
distances = {}
max_value = 10 ** 4
for i in range(2, max_value + 1):
	graph[i] = [i - 1]
	if i * 2 <= max_value:
		graph[i].append(i * 2)
path_length = 0
q = [n]
distances[n] = 0
used_to = [False] * (10 ** 4 + 1)
used_to[n] = True
while len(q) != 0:
	current_node = q.pop(0)
	if current_node == m:
		print(distances[m])
		exit(0)
	for node in graph[current_node]:
		if used_to[node] == False:
			q.append(node)
			distances[node] = distances[current_node] + 1
			used_to[node] = True


a = list(map(int, input().split()))
n = a[0]
m = a[1]
result = 0
if n >= m:
	result = n - m
else:
	while n != m:
		if n < m and m % 2 == 0:
			m /= 2
		else:
			m += 1
		result += 1
print(result)


from math import *
from copy import *
from string import *
from random import *
from sys import stdin
from sys import maxsize
from operator import *
from itertools import *
from collections import Counter
import math

def bin1(l, r, k, t, b, val, ans):
	if l > r:
		return ans
	else:
		mid = (l + r) // 2
		v = k ** mid
		if v == val:
			return v
		elif v > val:
			ans = mid
			return bin1(mid + 1, r, k, t, b, val, ans)
		else:
			return bin1(l, mid - 1, k, t, b, val, ans)

def bin2(l, r, k, t, b, val, ans):
	if l > r:
		return ans
	else:
		mid = (l + r) // 2
		v = t * k ** mid + b * mid
		if v == val:
			return v
		elif v > val:
			ans = mid
			return bin2(l, mid - 1, k, t, b, val, ans)
		else:
			return bin2(mid + 1, r, k, t, b, val, ans)

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime
(n, m) = map(int, input().split(' '))
if m <= n:
	print(n - m)
else:
	c = 0
	while m > n:
		if m % 2 == 0:
			c = c + 1
			m = m // 2
		else:
			c = c + 2
			m = (m + 1) // 2
	c = c + n - m
	print(c)


(x, y) = input().split()
x = int(x)
y = int(y)
soma = 0
while y > x:
	if y % 2 == 1:
		y += 1
		soma += 1
	else:
		y = y / 2
		soma += 1
soma += int(x - y)
print(soma)


(n, m) = map(int, input().split())
a = 0
while n != m:
	if True:
		a += 1
		m += 1 if m < n or m & 1 else -m // 2
print(a)


import queue

def bfs(a, b):
	q = queue.Queue()
	q.put((0, a))
	while True:
		(n, top) = q.get()
		if top == b:
			return n
		if vis[top]:
			continue
		vis[top] = True
		if top < b:
			q.put((n + 1, top * 2))
		if top - 1 >= 1:
			q.put((n + 1, top - 1))
(n, m) = map(int, input().split())
vis = [False for i in range(20100)]
print(bfs(n, m))


(n, m) = map(int, input().split())
coN = 0
while n != m:
	if m > n:
		if m % 2 == 0:
			m = m // 2
			coN += 1
		else:
			m += 1
			coN += 1
	elif n > m:
		m += 1
		coN += 1
print(coN)


(z, zz) = (input, lambda : list(map(int, z().split())))
fast = lambda : stdin.readline().strip()
zzz = lambda : [int(i) for i in stdin.readline().split()]
(szz, graph, mod, szzz) = (lambda : sorted(zz()), {}, 10 ** 9 + 7, lambda : sorted(zzz()))
from string import *
from re import *
from collections import *
from queue import *
from sys import *
from collections import *
from math import *
from heapq import *
from itertools import *
from bisect import *
from collections import Counter as cc
from math import factorial as f
from bisect import bisect as bs
from bisect import bisect_left as bsl
from itertools import accumulate as ac

def lcd(xnum1, xnum2):
	return xnum1 * xnum2 // gcd(xnum1, xnum2)

def prime(x):
	p = ceil(x ** 0.5) + 1
	for i in range(2, p):
		if x % i == 0 and x != 2 or x == 0:
			return 0
	return 1

def dfs(u, visit, graph):
	visit[u] = True
	for i in graph[u]:
		if not visit[i]:
			dfs(i, visit, graph)
(n, m) = zz()
ans = 0
if m <= n:
	print(n - m)
	exit(0)
while n != m:
	if m <= n:
		print(n - m + ans)
		exit(0)
	if m % 2 == 0:
		ans += 1
		m = m // 2
	else:
		m += 1
		ans += 1
print(ans)


from queue import Queue
(n, m) = (int(x) for x in input().split())
if m <= n:
	print(n - m)
	exit()
lvl = [-1] * 20001
lvl[n] = 0
q = Queue()
q.put(n)
while not q.empty():
	v = q.get()
	if v > 1 and lvl[v - 1] == -1:
		lvl[v - 1] = lvl[v] + 1
		q.put(v - 1)
	if v <= 10000 and lvl[v * 2] == -1:
		lvl[v * 2] = lvl[v] + 1
		q.put(v * 2)
print(lvl[m])


(n, m) = [int(i) for i in input().split()]
count = 0
if n > m:
	print(n - m)
else:
	while n < m:
		if m % 2 == 0:
			m /= 2
			count += 1
		else:
			m += 1
			count += 1
	count = int(abs(count + (n - m)))
	print(count)


(n, m) = [int(i) for i in input().strip().split(' ')]
targets = list()
targets.append(m)
while targets[-1] > n:
	next_target = targets[-1]
	if next_target % 2 == 1:
		targets.append(next_target + 1)
	else:
		targets.append(next_target / 2)
targets.reverse()
print(n - int(targets[0]) + len(targets) - 1)


(n, m) = map(int, input().split())
c = 0
while n < m:
	c += 1 + m % 2
	m = (m + m % 2) / 2
print(int(c + n - m))


(n, m) = map(int, input().split())
v = set()
s = [n]
g = {}
while s:
	x = s.pop()
	if x not in v:
		v.add(x)
		if x <= 1:
			s.append(2 * x)
			g[x] = [2 * x]
		elif x > m:
			s.append(x - 1)
			g[x] = [x - 1]
		else:
			s.append(x - 1)
			s.append(2 * x)
			g[x] = [x - 1, 2 * x]
v = [False] * 50000
d = [0] * 50000
q = [n]
v[n] = True
while q:
	s = q.pop(0)
	for u in g[s]:
		if v[u]:
			continue
		v[u] = True
		if d[u] == 0:
			d[u] = d[s] + 1
		else:
			d[u] = min(d[u], d[s] + 1)
		q.append(u)
print(d[m])


(n, m) = map(int, input().split())
if m < n:
	print(n - m)
elif m == n:
	print(0)
else:
	count = 0
	while m > n:
		if m & 1:
			m = int((m + 1) / 2)
			count += 1
		else:
			m = int(m / 2)
			first = 1
		count += 1
	count += abs(m - n)
	print(count)


nums = [int(i) for i in input().split()]
(a, b) = nums

def counter(n, m):
	count = 0
	if m % 2:
		count += 1
		m += 1
	while m != n:
		if m > n:
			if m % 2 == 0:
				m //= 2
			else:
				m += 1
			count += 1
		else:
			count += n - m
			m = n
	return count
print(counter(a, b))


(a, b) = map(int, input().split())
cont = 0
while True:
	if a >= b:
		cont += a - b
		break
	else:
		cont += 1
		if a * 2 == b:
			break
		else:
			b = [b // 2, b + 1][b % 2]
print(cont)


import math
line1 = input().split(' ')
n = int(line1[0])
m = int(line1[1])
v = m
t = 0
if n >= m:
	t = n - m
else:
	while v > n:
		if v % 2 == 0:
			v = v / 2
			t += 1
		else:
			v = (v + 1) / 2
			t += 2
	t = t + n - v
print(int(t))


from collections import defaultdict
(x, y) = map(int, input().split())
q = [x]
d = [1] * 40001
v = [0]
d[x] = 0
while 1:
	lol = q.pop(0)
	k = v.pop(0)
	if lol == y:
		break
	if d[lol - 1] and lol - 1 > 0:
		q.append(lol - 1)
		v.append(k + 1)
		d[lol - 1] = 0
	if d[2 * lol] and 2 * lol <= 2 * 10000:
		q.append(2 * lol)
		v.append(k + 1)
		d[2 * lol] = 0
print(k)


(n, m) = [int(i) for i in input().split()]
if n >= m:
	ans = n - m
else:
	count = 0
	while m != n:
		if m % 2 != 0 and m > n:
			m += 1
			m /= 2
			count += 1
		elif m > n and m % 2 == 0:
			m /= 2
		else:
			m += 1
		count += 1
	ans = count
print(ans)


from math import log2, ceil
(n, m) = map(int, input().split())
if n >= m:
	print(n - m)
else:
	k = ceil(log2(m / n))
	s = k
	d = int(n * 2 ** k) - m
	for i in range(k, -1, -1):
		j = d // int(2 ** i)
		d -= j * int(2 ** i)
		s += j
		if d == 0:
			break
	print(s)


(n, m) = map(int, input().split())
t = 0
if n > m:
	print(n - m)
else:
	while n < m:
		if m % 2 == 0:
			m = m / 2
			t += 1
		else:
			m = (m + 1) / 2
			t += 2
	print(int(abs(n - m) + t))


(n, m) = [int(x) for x in input().split(' ')]
d = 0

def main(n, m):
	global d
	if m == n:
		print(d)
		exit()
	if n >= m:
		d += n - m
		print(d)
		exit()
	elif m % 2 == 0:
		d += 1
		m //= 2
	else:
		d += 1
		m += 1
	return main(n, m)
main(n, m)


(n, m) = map(int, input().strip().split(' '))
if m <= n:
	print(n - m)
else:
	cont = 1
	pas = 0
	while m > n:
		n *= 2
		pas += 1
		cont *= 2
	tot = n - m
	while tot > 0:
		pas += tot // cont
		tot = tot % cont
		cont /= 2
	print(int(pas))


(start, end) = map(int, input().split())

def compute(start, end):
	if start >= end:
		return start - end
	elif end % 2 != 0:
		return 1 + compute(start, end + 1)
	else:
		return 1 + compute(start, end // 2)
print(compute(start, end))


from math import log
(n, m) = [int(i) for i in input().split()]
vis = {m: int(log(m, 2)) + 1 + n + pow(2, int(log(m, 2)) + 1) - m}
sta = [(n, 0)]
while len(sta) != 0:
	(curr, depth) = sta.pop()
	if curr in vis and vis[curr] <= depth or vis[m] <= depth or curr <= 0:
		continue
	vis[curr] = depth
	if curr == m:
		continue
	if curr > m:
		if m in vis:
			vis[m] = min(vis[m], depth + (curr - m))
		else:
			vis[m] = depth + (curr - m)
		continue
	sta.append((curr * 2, depth + 1))
	sta.append((curr - 1, depth + 1))
print(vis[m])


def buttons(n, m):
	moves = 0
	while n != m:
		if m % 2 != 0 or m < n:
			m += 1
		else:
			m = m / 2
		moves += 1
	return moves
(n, m) = map(int, input().split())
print(buttons(n, m))


def buttons(m, n, Steps):
	if m == n:
		return Steps
	elif m % 2 == 0 and m > n:
		return buttons(m // 2, n, Steps + 1)
	elif m % 2 == 1 and m > n:
		return buttons((m + 1) // 2, n, Steps + 2)
	else:
		return Steps + (n - m)
[n, m] = input().split(' ')
print(buttons(int(m), int(n), 0))


l = input()
l = l.split(' ')
n = int(l[0])
m = int(l[1])
ans = 0
while n < m:
	if m % 2 == 1:
		m += 1
		ans += 1
	m = m // 2
	ans += 1
if n >= m:
	ans += n - m
print(ans)


instr = list(map(int, input().split(' ')))
num = 0
while instr[0] < instr[1]:
	if instr[1] % 2:
		instr[1] += 1
	else:
		instr[1] //= 2
	num += 1
print(instr[0] - instr[1] + num)


def f(a, b):
	while a < b:
		a = 2 * a
	return a

def g(a, b):
	i = 0
	while a < b:
		a = 2 * a
		i += 1
	return i

def judge(a, b):
	if a >= b:
		return a - b
	elif b % 2 == 0:
		if b == 2 * a:
			return 1
		elif f(a, b) == b:
			return min(judge(a, b // 2) + 1, g(a, b))
		else:
			return min(judge(a, b // 2) + 1, judge(a, f(a, b)) + f(a, b) - b)
	else:
		return judge(a, b + 1) + 1
x = input().split()
n = int(x[0])
m = int(x[1])
print(judge(n, m))


def bfs(n, m):
	stack = [n]
	counter = 0
	if n == m:
		print(0)
	else:
		while stack:
			counter += 1
			n_i = stack.pop(0)
			if m in apuntadores[n_i]:
				print(contadores[n_i])
				break
			else:
				for a in apuntadores[n_i]:
					if not visitados[a]:
						contadores[a] = contadores[n_i] + 1
						stack.append(a)
						visitados[a] = True
values = list(map(int, input().split()))
n = values[0]
m = values[1]
apuntadores = {}
contadores = {}
for i in range(0, 10001):
	contadores.update({i: 1})
	if i <= 5000:
		apuntadores.update({i: (i - 1, 2 * i)})
	else:
		apuntadores.update({i: (i - 1, 0)})
visitados = [False] * apuntadores.__len__()
visitados[0] = True
bfs(n, m)


def solve(a, b):
	big = float('inf')
	small = float('-inf')
	if a == b:
		return 0
	elif a > b:
		steps = a - b
		return steps
	else:
		(ab, bb) = (a, b)
		steps = 0
		while a < b:
			last = a
			a *= 2
			steps += 1
		steps += a - b
		nsteps = 0
		while ab < bb:
			last = bb
			nsteps += 1
			rem = 0
			if bb % 2 != 0:
				nsteps += 1
				rem += 1
			bb //= 2
			bb += rem
		nsteps += ab - bb
	return min(steps, nsteps)

def main():
	d = input()
	d = [int(i) for i in d.split()]
	a = d[0]
	b = d[1]
	ans = solve(a, b)
	print(ans)
main()


import math
(start, end) = map(int, input().split(' '))
if start > end:
	print(start - end)
else:
	temp_start = start
	temp_end = end
	step_down = 0
	while temp_end > temp_start:
		if temp_end % 2 != 0:
			temp_end += 1
			step_down += 1
		temp_end = temp_end / 2
		step_down = step_down + 1
	step_down = step_down + (temp_start - temp_end)
	step_up = 0
	temp_start = start
	temp_end = end
	while temp_start < temp_end:
		temp_start *= 2
		step_up = step_up + 1
	step_up = step_up + (temp_start - temp_end)
	print(int(min(step_up, step_down)))


l = list(map(int, input().split()))
n = l[0]
m = l[1]
if m < n:
	print(n - m)
else:
	r = 0
	while m != n:
		if m < n:
			r += n - m
			break
		if m % 2 == 0:
			r += 1
			m = int(m / 2)
		else:
			r += 1
			m += 1
	print(r)


import sys
fast_reader = sys.stdin.readline
fast_writer = sys.stdout.write

def input():
	return fast_reader().strip()

def print(*argv):
	fast_writer(' '.join((str(i) for i in argv)))
	fast_writer('\n')
for _ in range(1):
	(n, m) = map(int, input().split())
	ans = 0
	while m > n:
		if m % 2 == 0:
			m = m // 2
		else:
			m += 1
		ans += 1
	print(ans + (n - m))


(a, b) = list(map(int, input().split()))
if a >= b:
	print(a - b)
else:
	p = 0
	while True:
		if b % 2 == 0:
			p += 1
			b = b // 2
		else:
			p += 2
			b = b // 2 + 1
		if a >= b:
			p += a - b
			break
	print(p)


(x, y) = (int(x) for x in input().split())

def but(x, y):
	if x == y:
		return 0
	if x >= y:
		return x - y
	if y % 2 == 0:
		return 1 + but(x, y // 2)
	else:
		return 1 + but(x, y + 1)
print(but(x, y))


def findMin(n, m):
	sum = 0
	if n >= m:
		return n - m
	while n < m:
		if m % 2 != 0:
			m += 1
		else:
			m //= 2
		sum += 1
	return sum + (n - m)
(n, m) = [int(x) for x in input().split()]
print(findMin(n, m))


lst = [int(i) for i in input().split()]
a = lst[0]
b = lst[1]
if b <= a:
	print(a - b)
else:
	i = 0
	while b != a:
		while b % 2 == 0 and b > a:
			b = b / 2
			i += 1
		if b != a:
			b += 1
			i += 1
	print(i)


def mi(m, n):
	if m == n:
		return 0
	if m > n:
		return m - n
	if m <= 0 and n > 0:
		return -1
	if n % 2 == 1:
		return 1 + mi(m, n + 1)
	else:
		return 1 + mi(m, n // 2)
(m, n) = map(int, input().split())
print(mi(m, n))


(n, m) = input().split()
a = int(n)
b = int(m)
count = 0
while b > a:
	if b % 2 == 1:
		count = count + 1
		b = b + 1
	else:
		b = b // 2
		count = count + 1
count = count + (a - b)
print(count)


import sys
sys.setrecursionlimit(100000000)
s = input()
s = s.split()
n = int(s[0])
m = int(s[1])
c = 0

def solve(n, m, c):
	if m < n:
		return n - m + c
	if m == n:
		return c
	elif m % 2 == 0:
		return solve(n, int(m / 2), c + 1)
	else:
		return solve(n, m + 1, c + 1)
print(solve(n, m, 0))


(n, m) = map(int, input().split())
if n == m:
	print(0)
if n > m:
	num = n - m
	print(num)

def bfs(nohdepartida, nohdechegada):
	nivel = []
	for i in range(10002):
		nivel.append(-1)
	fila = []
	fila.append(n)
	nivel[n] = 0
	while len(fila) > 0:
		nohtop = fila.pop()
		if nohtop == m:
			print(nivel[nohtop])
			break
		if 2 * nohtop <= 10000:
			if nivel[2 * nohtop] == -1:
				nivel[2 * nohtop] = nivel[nohtop] + 1
				fila.insert(0, 2 * nohtop)
		if nohtop > 1:
			if nivel[nohtop - 1] == -1:
				nivel[nohtop - 1] = nivel[nohtop] + 1
				fila.insert(0, nohtop - 1)
if m > n:
	bfs(n, m)


x = input()
x = x.split(' ')
y = int(x[1])
x = int(x[0])
save_set = set()
second_set = set()
dict_set = set()
save_set.add(x)
count = 0
while True:
	if y in save_set:
		print(count)
		break
	for num in save_set:
		if num - 1 not in dict_set:
			second_set.add(num - 1)
			dict_set.add(num - 1)
		if num < y and num * 2 not in dict_set:
			second_set.add(num * 2)
			dict_set.add(num * 2)
	count += 1
	save_set = set(second_set)
	second_set = set()


(n, m) = map(int, input().split())
maxn = 30000.0 + 1
lay = [0 for _ in range(int(30000.0 + 1))]
vis = [0 for _ in range(int(30000.0 + 1))]

def bfs(now):
	(cnt, head, tail) = (0, 0, 0)
	que = [0 for i in range(int(100000.0))]
	(que[tail], tail) = (now, tail + 1)
	while tail > head:
		(fa, head) = (que[head], head + 1)
		if vis[fa] == 1:
			continue
		vis[fa] = 1
		if fa == m:
			return lay[fa]
		if fa > 0 and fa < 30000.0:
			if fa - 1 > 0:
				(que[tail], tail, lay[fa - 1]) = (fa - 1, tail + 1, lay[fa] + 1)
			if fa * 2 < 30000.0:
				(que[tail], tail, lay[fa * 2]) = (fa * 2, tail + 1, lay[fa] + 1)
	return -1
print(bfs(n))


import sys
(n, m) = map(int, sys.stdin.readline().split())
counter = 0
if n > m:
	counter = n - m
else:
	while m - n != 0:
		if m % 2 == 0 and m > n:
			m /= 2
			counter += 1
		else:
			if n >= m:
				counter += n - m
				break
			m = (m + 1) / 2
			counter += 2
print(int(counter))


def bfs(start, goal):
	moves = 0
	q = [start]
	seen = set()
	while q:
		for _ in range(len(q)):
			num = q.pop(0)
			if num < 1 or num > 10 ** 4:
				continue
			if num == goal:
				return moves
			seen.add(num)
			if num * 2 not in seen:
				q.append(num * 2)
			if num - 1 not in seen:
				q.append(num - 1)
		moves += 1
	return moves
test = input()
(s, g) = test.split(' ')
print(bfs(int(s), int(g)))


ri = lambda : map(int, input().split(' '))
(n, m) = ri()
seen = set()
q = [(n, 0)]
seen.add(n)
while q:
	(x, t) = q[0]
	q.pop(0)
	if x == m:
		import sys
		print(t)
		sys.exit(0)
	if x > 1 and x - 1 not in seen:
		seen.add(x - 1)
		q.append((x - 1, t + 1))
	if x < m and 2 * x not in seen:
		seen.add(2 * x)
		q.append((2 * x, t + 1))


inp = input().split()
n = int(inp[0])
m = int(inp[1])
import math

def numButtons(n, m):
	if m < 0 or n == m:
		return 0
	if n > m:
		return n - m
	elif m % 2 == 0:
		return numButtons(n, int(m / 2)) + 1
	else:
		return numButtons(n, int(m / 2) + 1) + 2
print(numButtons(n, m))


from __future__ import division, print_function
import itertools, os, sys, threading
from collections import deque, Counter, OrderedDict, defaultdict
from atexit import register
from io import BytesIO, StringIO

def ii():
	return int(input())

def si():
	return str(input())

def mi():
	return map(int, input().strip().split(' '))

def li():
	return list(mi())

def getKey(item):
	return item[0]

def sort2(l):
	return sorted(l, key=getKey)

def d2(n, num):
	return [[num for x in range(n)] for y in range(n)]

def ntl(n):
	return [int(i) for i in str(n)]

def powerMod(x, y, p):
	res = 1
	x %= p
	while y > 0:
		if y & 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x
abc = 'abcdefghijklmnopqrstuvwxyz'
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}

def main():
	(n, m) = mi()
	q = [[n, 0]]
	f = [-1] * 100005
	while len(q) != 0:
		a = q[0][0]
		b = q[0][1]
		if a == m:
			print(b)
			break
		f[a] = 1
		q.pop(0)
		if a < m and f[2 * a] == -1:
			q.append([2 * a, b + 1])
		if a > 1 and f[a - 1] == -1:
			q.append([a - 1, b + 1])
main()


(n, m) = [int(x) for x in input().split()]
if n >= m:
	print(n - m)
if n < m:
	a = m
	red = 0
	blue = 0
	while a > n:
		if a % 2 == 0:
			red += 1
			a = int(a / 2)
		else:
			red += 1
			blue += 1
			a = int((a + 1) / 2)
	blue += n - a
	print(blue + red)


import sys
from math import sqrt, gcd, ceil, log
from collections import defaultdict, Counter, deque
input = sys.stdin.readline
read = lambda : list(map(int, input().strip().split()))

def main():
	(n, m) = read()
	adj = defaultdict(list)
	Z = 2 * 10 ** 4 + 1
	adj[1].append(2)
	for i in range(2, Z):
		adj[i].append(i * 2)
		adj[i].append(i - 1)
	que = deque([(n, 0)])
	visited = defaultdict(int)
	visited[n] = 1
	while que:
		par = que.popleft()
		(num, d) = par
		if num == m:
			print(d)
			break
		for child in adj[num]:
			if not visited[child]:
				visited[child] = 1
				que.append((child, d + 1))
main()


(n, m) = [int(x) for x in input().split()]

def solve(n, m):
	if n >= m:
		return n - m
	elif m % 2 == 0:
		return 1 + solve(n, m // 2)
	else:
		return 2 + solve(n, (m + 1) // 2)
print(solve(n, m))


a = input().split()
n = int(a[0])
m = int(a[1])
k = 0
if m < n:
	k = n - m
else:
	while m != n:
		if m < n:
			m += 1
			k += 1
		elif m % 2 == 0:
			m /= 2
			k += 1
		else:
			m += 1
			k += 1
print(k)


from math import ceil

def solve(n, m):
	if n >= m:
		return (n - m, m)
	(operations, new) = solve(n, ceil(m / 2))
	return (operations + (2 * new - m) + 1, m)
(n, m) = map(int, input().split())
print(solve(n, m)[0])


(n, k) = map(int, input().split())
c = 0
while n < k:
	if k % 2 == 1:
		k += 1
		c += 1
	else:
		k = k // 2
		c += 1
c += abs(n - k)
print(c)


(n, m) = list(map(lambda x: int(x), input().split()))
if n > m:
	print(n - m)
elif n == m:
	print(0)
elif m // n == 2:
	print(1)
else:
	count = 0
	while m > n:
		if m % 2 == 0:
			m = m // 2
		else:
			m = m + 1
		count += 1
	if m == n:
		print(count)
	else:
		count += n - m
		print(count)


from sys import stdin, stdout
import math
cin = stdin.readline
cout = stdout.write
(n, m) = map(int, cin().split())
if n >= m:
	cout(str(n - m))
	exit(0)
qu = [n]
visited = [-1] * (m * 2 + 1)
visited[n] = 0
ans = 10 ** 5
while len(qu) > 0:
	x = qu[0]
	if x >= m:
		ans = min(ans, x - m + visited[x])
	else:
		if visited[x * 2] == -1:
			qu.append(x * 2)
			visited[x * 2] = visited[x] + 1
		if x > 1 and visited[x - 1] == -1:
			qu.append(x - 1)
			visited[x - 1] = visited[x] + 1
	qu.pop(0)
cout(str(ans))


(n, m) = map(int, input().split(' '))

class Fila(list):

	def __init__(self):
		super(Fila, self).__init__()
		self.max_N = 10010
		self.queue = []
		self.memo = [False for _ in range(self.max_N)]

	def is_empty(self):
		return len(self.queue) == 0

	def push(self, element):
		if element[0] < 1 or element[0] >= self.max_N:
			return
		if self.memo[element[0]]:
			return
		self.memo[element[0]] = True
		self.queue.append(element)

	def pop(self):
		if not self.is_empty():
			top = self.queue[0]
			self.queue = self.queue[1:] if len(self.queue) > 1 else []
			return top
		raise Error('The queue is empty!')
fila = Fila()
fila.push((n, 0))
while not fila.is_empty():
	(top, step) = fila.pop()
	if top == m:
		print(step)
		break
	fila.push((top - 1, step + 1))
	fila.push((top * 2, step + 1))


def fun(x, y, c):
	if x == y:
		print(c)
	elif y > x:
		if y % 2 == 0:
			c += 1
			fun(x, y / 2, c)
		else:
			c += 1
			fun(x, y + 1, c)
	else:
		print(int(x - y + c))
(n, m) = input().split()
n = int(n)
m = int(m)
fun(n, m, 0)


def bfs(graph, begin):
	d = [None] * len(graph)
	d[begin] = 0
	vertices = [begin]
	cur_d = 1
	while len(vertices) > 0:
		s_ver = []
		for v in vertices:
			for u in graph[v]:
				if d[u] is None:
					d[u] = cur_d
					s_ver.append(u)
		vertices = s_ver
		cur_d += 1
	return d
(n, m) = list(map(int, input().split()))
graph = [[] for _ in range(max(n, m) * 2 + 1)]
for i in range(1, max(n, m) * 2 + 1):
	if i - 1 > 0:
		graph[i].append(i - 1)
	if i * 2 <= max(n, m) * 2:
		graph[i].append(i * 2)
print(bfs(graph, n)[m])


arr = list(map(int, input().split()))
n = arr[0]
m = arr[1]
if m <= n:
	print(n - m)
else:
	c = 0
	t = n
	while not (t <= m and m <= 2 * t):
		t *= 2
		c += 1
	l = [0] * (2 * t + 1)
	for i in range(1, n):
		l[i] = n - i
	h = n
	stk = [n]
	c = 0
	while h <= t:
		h *= 2
		stk.append(h)
		c += 1
		l[h] = c
	f = len(stk)
	i = 0
	while i != f - 1:
		st = stk[i]
		end = stk[i + 1]
		for j in range(end - 1, st, -1):
			if j % 2 == 1:
				l[j] = l[j + 1] + 1
			else:
				l[j] = min(l[j // 2] + 1, l[j + 1] + 1)
		i += 1
	print(l[m])


def Solve(n, m):
	moves = 0
	stack = [(n, 0)]
	count = 0
	vals = set()
	while stack:
		curr = stack.pop(0)
		k = curr[0]
		moves = curr[1]
		if k not in vals:
			vals.add(k)
			if k == m:
				optimal = moves
			if 2 * k - m <= n:
				stack.append((k * 2, moves + 1))
			if k - 1 >= 0:
				stack.append((k - 1, moves + 1))
	return optimal

def main():
	(n, m) = map(int, input().split())
	print(Solve(n, m))
main()


inp = input().split()
num1 = int(inp[0])
num2 = int(inp[1])

def least_presses(start, goal):
	curr = list()
	curr.append(start)
	visited = list()
	visited.append(start)
	steps = 0
	while True:
		next = list()
		for num in curr:
			if num * 2 not in visited and num <= -(-goal // 2):
				if num * 2 == goal:
					return steps + 1
				visited.append(num * 2)
				next.append(num * 2)
			if num - 1 not in visited and num > 1:
				if num - 1 == goal:
					return steps + 1
				visited.append(num - 1)
				next.append(num - 1)
		curr = next
		steps += 1
print(least_presses(num1, num2))


inlet = input().split(' ')
(n, m) = (int(inlet[0]), int(inlet[1]))
cont = 0
while m > n:
	if m // 2 != m / 2:
		cont += 1
		m += 1
	m = m // 2
	cont += 1
if n >= m:
	print(n - m + cont)
	exit()


inpt = input().split()
n = int(inpt[0])
m = int(inpt[1])
moves = 0
while m != n:
	if m % 2 == 1 or m < n:
		m += 1
		moves += 1
	else:
		m = m / 2
		moves += 1
print(moves)


import os
import sys
import math
import collections
import itertools

def get_int():
	return int(input())

def get_ints():
	return map(int, input().split())

def get_strs():
	return input().split()

def get_float():
	return float(input())

def get_floats():
	return map(float, input().split())

def list_strs():
	return list(input().split())

def list_ints():
	return list(map(int, input().split()))

def list_floats():
	return list(map(float, input.split()))

def post(x):
	print(x, end=' ')
(n, m) = get_ints()
counter = 0
while n != m:
	if n > m:
		counter += n - m
		n = m
	elif n < m:
		if m % 2 == 0:
			counter += 1
			m //= 2
		else:
			counter += 1
			m += 1
print(counter)


import sys
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
numbers = list(invr())
n = numbers[0]
m = numbers[1]
if m < n:
	print(n - m)
else:
	count = 0
	while m > n:
		if m % 2 != 0:
			m = m + 1
			count = count + 1
		else:
			count = count + 1
			m = m / 2
	print(int(count + (n - m)))


(n, m) = map(int, input().split(' '))
b = 1
r = 2
i = 0
if n >= m:
	while n > m:
		n -= b
		i += 1
elif n < m:
	while n < m:
		if m % 2 == 0:
			m //= 2
		else:
			m += 1
		i += 1
	while n > m:
		n -= b
		i += 1
print(i)


class Graph:
	adj_list = {}
	num_vertices = 0
	visited = set()

	def __init__(self, start, end, num_vertices):
		self.start = start
		self.end = end
		self.adj_list = {}
		self.num_vertices = num_vertices
		self.visited = set()
		self.path = [None] * (num_vertices * 4 + 1)

	def generate_edges(self):
		self.adj_list[1] = [2]
		for i in range(2, self.num_vertices * 2 + 1):
			self.adj_list[i] = [i - 1, 2 * i]
		for i in range(self.num_vertices * 2 + 1, self.num_vertices * 4 + 1):
			self.adj_list[i] = [i - 1]
		for i in range(1, self.num_vertices * 4 + 1):
			self.path[i] = None
		print(self.bfs())

	def bfs(self):
		queue = [self.start]
		self.visited.add(self.start)
		self.path[self.start] = 0
		while queue:
			v = queue.pop(0)
			vlna = self.path[v]
			for node in self.adj_list[v]:
				if node not in self.visited:
					if self.path[node] is None or self.path[node] > vlna:
						self.path[node] = vlna + 1
					self.visited.add(node)
					queue.append(node)
				if node == self.end:
					return self.path[node]
list_n_m = input().split()
list_n_m = [int(i) for i in list_n_m]
n = int(list_n_m[0])
m = int(list_n_m[1])
g = Graph(n, m, max(list_n_m))
g.generate_edges()


(n, m) = [int(x) for x in input().split()]
cnt = 0
rst = 0
if n >= m:
	rst = n - m
else:
	while n != m:
		if m < n:
			m += 1
		elif m % 2 != 0:
			m += 1
		else:
			m /= 2
		cnt += 1
	rst = cnt
print(rst)


from sys import stdin, stdout
from math import floor, gcd, fabs, factorial, fmod, sqrt, inf, log
from collections import defaultdict as dd, deque
from heapq import merge, heapify, heappop, heappush, nsmallest
from bisect import bisect_left as bl, bisect_right as br, bisect
mod = pow(10, 9) + 7
mod2 = 998244353

def inp():
	return stdin.readline().strip()

def out(var, end='\n'):
	stdout.write(str(var) + '\n')

def outa(*var, end='\n'):
	stdout.write(' '.join(map(str, var)) + end)

def lmp():
	return list(mp())

def mp():
	return map(int, inp().split())

def smp():
	return map(str, inp().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(m, val) for j in range(n)]

def remadd(x, y):
	return 1 if x % y else 0

def ceil(a, b):
	return (a + b - 1) // b

def isprime(x):
	if x <= 1:
		return False
	if x in (2, 3):
		return True
	if x % 2 == 0:
		return False
	for i in range(3, int(sqrt(x)) + 1, 2):
		if x % i == 0:
			return False
	return True
(n, m) = mp()
ans = 0
while n < m:
	if m % 2:
		m += 1
	else:
		m //= 2
	ans += 1
print(ans + n - m)


import sys
(n, m) = input().split()
n = int(n)
m = int(m)
numero_cliques = 0
if m < n:
	print(n - m)
	sys.exit()
elif m > n:
	while n < m:
		if m % 2 == 0:
			m = m / 2
		elif m % 2:
			m += 1
		numero_cliques += 1
print(int(abs(numero_cliques + n - m)))


(n, m) = map(int, input().strip().split())
presses = 0
while n < m:
	if m % 2 == 0:
		m //= 2
	else:
		m += 1
	presses += 1
presses += n - m
print(presses)


import sys
import math
from sys import stdin, stdout

def sieve(N):
	primeNumbers = [True] * (N + 1)
	primeNumbers[0] = False
	primeNumbers[1] = False
	i = 2
	while i * i <= N:
		j = i
		if primeNumbers[j]:
			while j * i <= N:
				primeNumbers[j * i] = False
				j += 1
		i += 1
	return primeNumbers

def getPrime(N):
	primes = sieve(N)
	result = []
	for i in range(len(primes)):
		if primes[i]:
			result.append(i)
	return result

def factor(N):
	factors = []
	i = 1
	while i * i <= N:
		if N % i == 0:
			factors.append(i)
			if i != N // i:
				factors.append(N // i)
		i += 1
	return sorted(factors)

def gcd(a, b):
	if a < b:
		return gcd(b, a)
	if b == 0:
		return a
	return gcd(b, a % b)

def extendedGcd(a, b):
	if a < b:
		return extendedGcd(b, a)
	if b == 0:
		return [a, 1, 0]
	res = extendedGcd(b, a % b)
	x = res[2]
	y = res[1] - math.floor(a / b) * res[2]
	res[1] = x
	res[2] = y
	return res

def iterativeModularFunc(a, b, c):
	res = 1
	while b > 0:
		if b & 1:
			res = res * a % c
		a = a * a % c
		b = b // 2
	return res

def get_ints_in_variables():
	return map(int, sys.stdin.readline().strip().split())

def get_int():
	return int(input())

def get_ints_in_list():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_list_of_list(n):
	return [list(map(int, sys.stdin.readline().strip().split())) for _ in range(n)]

def get_string():
	return sys.stdin.readline().strip()

def Solution(n, m):
	count = 0
	while m > n:
		if m % 2 == 0:
			m = m // 2
			count += 1
		else:
			count += 1
			m += 1
	print(count + n - m)

def main():
	(n, m) = get_ints_in_variables()
	Solution(n, m)
main()


from queue import Queue
import random

def brute(n, m):
	q = Queue()
	seen = set([])
	q.put((n, 0))
	while not q.empty():
		(curr, numClicks) = q.get()
		if curr in seen:
			continue
		if curr == m:
			return numClicks
		if curr >= 2 * max(m, n) or curr <= min(m, n) // 2:
			continue
		seen.add(curr)
		nxts = [curr - 1, 2 * curr]
		random.shuffle(nxts)
		for nxt in nxts:
			q.put((nxt, numClicks + 1))
	return -1

def soln(n, m):
	if m <= n:
		return n - m
	if m % 2 == 1:
		return 1 + soln(n, m + 1)
	return 1 + soln(n, m // 2)

def main():
	(n, m) = [int(x) for x in input().split()]
	result = soln(n, m)
	print(result)
import random

def randomTest():
	T = 100
	N = 10001
	M = 10001
	for t in range(T):
		n = random.randint(1, N)
		m = random.randint(1, N)
		print(t, n, m)
		b = brute(n, m)
		f = soln(n, m)
		try:
			assert b == f
		except:
			print('Failed!')
			print(b, f)
			return
main()


from queue import *
(n, m) = map(int, input().split(' '))
q = Queue()
q.put((n, 0))
visited = [False for i in range(10010)]
while not q.empty():
	x = q.get()
	if x[0] - 1 == m or x[0] * 2 == m:
		print(x[1] + 1)
		break
	if x[0] < 0 or x[0] > 10000:
		continue
	if visited[x[0]]:
		continue
	visited[x[0]] = True
	q.put((x[0] - 1, x[1] + 1))
	q.put((x[0] * 2, x[1] + 1))


import math
import sys
from collections import defaultdict
from collections import Counter
from collections import deque
import bisect
sys.setrecursionlimit(1000000)
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
ilele = lambda : map(int, input().split())
alele = lambda : list(map(int, input().split()))
(n, m) = ilele()
if n >= m:
	print(n - m)
else:
	count = 0
	while m > n:
		if m % 2 != 0:
			m += 1
		else:
			m = m // 2
		count += 1
	print(count + n - m)


from sys import stdin, stdout
input = stdin.readline
(n, m) = map(int, input().split())
q = [(n, 0)]
v = [False] * (10 ** 4 + 1)
i = 0
while q:
	a = q[i][0] * 2
	b = q[i][0] - 1
	ans = q[i][1] + 1
	if a == m or b == m:
		stdout.write(str(ans))
		exit(0)
	if 1 <= a <= 10 ** 4:
		if not v[a]:
			q.append((a, ans))
			v[a] = True
	if 1 <= b <= 10 ** 4:
		if not v[b]:
			q.append((b, ans))
			v[b] = True
	i += 1


def fun(n, m):
	if n == m:
		return 0
	if m < n:
		return n - m
	c = 0
	while m > n:
		if m % 2 == 0:
			m //= 2
		else:
			m += 1
		c += 1
	return c + n - m
(n, m) = map(int, input().split())
print(fun(n, m))


import math

def buttons(n, m):
	if abs(m / 2 - n) == 1:
		return 1 + display(n - 1, m / 2)

def display(n, m):
	if n == m:
		return 0
	if n < m:
		if m % 2 != 0:
			return 1 + display(n, m + 1)
		return 1 + display(n, m // 2)
	return n - m
(n, m) = input().split()
n = int(n)
m = int(m)
print(display(n, m))


import math
(n, m) = map(int, input().split())
if m <= n:
	print(n - m)
else:
	ans = 0
	while m != n:
		if m % 2 == 0 and m > n:
			m /= 2
			ans += 1
		else:
			m += 1
			ans += 1
	print(ans)


import queue
max_n = 10 ** 4 * 2 + 1

def bfs(n, m):
	D = [-1] * max_n
	D[n] = 0
	fila = queue.Queue()
	fila.put(n)
	while not fila.empty():
		botoes = fila.get()
		(red, blue) = (botoes - 1, botoes * 2)
		if red < 0 or blue > max_n:
			continue
		for c in [red, blue]:
			if D[c] == -1:
				D[c] = D[botoes] + 1
				fila.put(c)
	return D[m]
(n, m) = map(int, input().split())
print(bfs(n, m))


(n, m) = [int(x) for x in input().split()]
t = 0
while n != m:
	if n >= m:
		t += n - m
		break
	elif n < m and m % 2 == 0:
		m /= 2
		t += 1
	else:
		m += 1
		t += 1
print(int(t))


from copy import deepcopy
(n, m) = (int(x) for x in input().split())
if n >= m:
	print(n - m)
else:
	count = 0
	while m > n:
		if m % 2 == 0:
			count += 1
			m //= 2
		else:
			count += 2
			m = (m + 1) // 2
	print(count + n - m)


numbers = input().split()
numbers[0] = int(numbers[0])
numbers[1] = int(numbers[1])

def NumPress(numbers):
	if numbers[0] >= numbers[1]:
		return numbers[0] - numbers[1]
	length = 0
	visited = []
	OldQueue = [numbers[0]]
	NewQueue = []
	while 1 == 1:
		length = length + 1
		add = True
		for i in range(len(OldQueue)):
			if OldQueue[i] - 1 == numbers[1]:
				return length
			if OldQueue[i] - 1 > 0:
				if OldQueue[i] - 1 not in visited:
					NewQueue.append(OldQueue[i] - 1)
					visited.append(OldQueue[i] - 1)
			if OldQueue[i] * 2 == numbers[1]:
				return length
			if OldQueue[i] < numbers[1]:
				NewQueue.append(OldQueue[i] * 2)
				visited.append(OldQueue[i] * 2)
		OldQueue = NewQueue
		NewQueue = []
print(NumPress(numbers))


from sys import stdin, stdout
input = stdin.readline
(n, m) = map(int, input().split())
from queue import Queue
q = Queue()
q.put((n, 0))
v = [False] * (10 ** 4 + 1)
while True:
	cur = q.get()
	a = cur[0] * 2
	b = cur[0] - 1
	ans = cur[1] + 1
	if a == m or b == m:
		stdout.write(str(ans))
		exit(0)
	if 1 <= a <= 10 ** 4:
		if not v[a]:
			q.put((a, ans))
			v[a] = True
	if 1 <= b <= 10 ** 4:
		if not v[b]:
			q.put((b, ans))
			v[b] = True


(n, m) = map(int, input().split())
q = [n]
visit = {}
dist = {n: 0}
while len(q) != 0:
	nod = q.pop(0)
	if nod == m:
		print(dist[m])
		break
	if nod - 1 not in visit and nod - 1 > 0:
		visit[nod - 1] = 1
		dist[nod - 1] = dist[nod] + 1
		q.append(nod - 1)
	if nod * 2 not in visit and nod < m:
		visit[nod * 2] = 1
		dist[nod * 2] = dist[nod] + 1
		q.append(nod * 2)


import queue
(n, m) = (int(_) for _ in input().split(' '))
if n >= m:
	print(n - m)
else:
	q = queue.PriorityQueue()
	q.put((0, n))
	found = False
	seen = set()
	while not q.empty() and (not found):
		(i, c) = q.get()
		if c == m:
			print(i)
			found = True
			continue
		if c in seen:
			continue
		seen.add(c)
		if c - 1 > 0:
			q.put((i + 1, c - 1))
		if c < m:
			if 2 * c <= m:
				q.put((i + 1, 2 * c))
			else:
				q.put((i + 1 + 2 * c - m, m))


import sys
import math as m
(a, b) = map(int, input().split(' '))
l = [sys.maxsize for i in range(2 * max(a, b) + 1)]
l[a] = 0

def ans2(a, b, steps, l, c):
	q = [[a, 0]]
	while len(q) != 0:
		n = q.pop(0)
		l[n[0]] = min(l[n[0]], n[1])
		if n[0] == b:
			return n[1]
		s = n[1]
		v = n[0]
		if v - 1 > 0:
			if l[v - 1] > s + 1:
				q.append([v - 1, s + 1])
		if 2 * v < 2 * max(b, c):
			if l[2 * v] > s + 1:
				q.append([2 * v, s + 1])
print(ans2(a, b, 0, l, a))


def bfs(n, m):
	parent = [-1] * (10 * m)
	q = list()
	q.append(n)
	parent[n] = n
	while len(q) != 0:
		child = q.pop()
		if child == m:
			break
		if child > 2 * m:
			continue
		if child * 2 < len(parent) and parent[child * 2] == -1:
			q.append(child * 2)
			parent[child * 2] = child
		if child - 1 >= 0 and parent[child - 1] == -1:
			parent[child - 1] = child
			q.append(child - 1)
	leaf = m
	cnt = 0
	print(parent)
	while parent[leaf] != n:
		cnt += 1
		leaf = parent[leaf]
	return cnt + 1

def main():
	(n, m) = [int(t) for t in input().split()]
	if n >= m:
		print(n - m)
		return
	cnt = 0
	while m != n:
		if m > n and m % 2 == 0:
			m /= 2
		elif m < n or (m > n and m % 2 != 0):
			m += 1
		m = int(m)
		cnt += 1
	print(cnt)
main()


import math
(m, n) = [int(i) for i in input().split()]
if n < m:
	print(m - n)
else:
	dp = [0] * (n + 1)
	for i in range(1, m):
		dp[i] = m - i
	for i in range(m + 1, n + 1):
		temp = int(math.ceil(i / m))
		num = m * int(pow(2, temp - 1))
		c = temp - 1
		c += num - i
		dp[i] = c
		if i % 2 == 0:
			temp = i // 2
			c2 = dp[temp] + 1
			dp[i] = min(c, c2)
		else:
			temp = (i + 1) // 2
			c2 = dp[temp] + 2
			dp[i] = min(c, c2)
	print(dp[-1])


def solve(s, e):
	out = 0
	while s < e:
		if e % 2 == 0:
			out += 1
		else:
			out += 2
		e = (e + 1) // 2
	return out + s - e
(n, m) = map(int, input().split())
print(solve(n, m))


def min_Push(n, m):
	if m > n:
		if m % 2 == 0:
			return 1 + min_Push(n, m / 2)
		else:
			return 1 + min_Push(n, m + 1)
	else:
		return n - m
nums = input().split()
n = int(nums[0])
m = int(nums[1])
print(int(min_Push(n, m)))


(n, m) = map(int, input().split())
q = [n]
d = {n: 0}
while q:
	n = q.pop(0)
	j = n * 2
	k = n - 1
	if d.get(j, -1) == -1 and j > -1 and (j <= 20001):
		d[j] = d[n] + 1
		q.append(j)
	if d.get(k, -1) == -1 and k > -1 and (k <= 20001):
		d[k] = d[n] + 1
		q.append(k)
print(d[m])


def main():
	(n, m) = map(int, input().split())
	(res, delta) = (0, 1)
	while n < m:
		res += 1
		n *= 2
		delta *= 2
	while n > m:
		while n - delta >= m:
			res += 1
			n -= delta
		delta //= 2
	print(res)

def __starting_point():
	main()
__starting_point()


from heapq import heappush, heappop
splitted = input().split(' ')
n = int(splitted[0])
m = int(splitted[1])
fringe = list()
heappush(fringe, (0, n))
s = set()
while len(fringe) > 0:
	cur = heappop(fringe)
	level = cur[0]
	num = cur[1]
	if num in s:
		continue
	else:
		s.add(num)
	if num == m:
		print(level)
		break
	if num < m:
		heappush(fringe, (level + 1, num * 2))
	if num > 1:
		heappush(fringe, (level + 1, num - 1))


(n, m) = map(int, input().split())
color = {}
dist = {}

def bfs(start):
	st = [start]
	color[start] = 1
	dist[start] = 0
	while st:
		v = st.pop(0)
		if v > 1 and v - 1 not in color.keys():
			color[v - 1] = 1
			dist[v - 1] = dist[v] + 1
			st.append(v - 1)
		if v < m and v * 2 not in color.keys():
			color[v * 2] = 1
			dist[v * 2] = dist[v] + 1
			st.append(v * 2)
		if m in color.keys():
			print(dist[m])
			break
bfs(n)


(a, b) = input().split()
a = int(a)
b = int(b)
count = 0

def get_min(a, b):
	global count
	if b >= a:
		if b == a:
			return count
		if b % 2 == 0:
			count += 1
			get_min(a, b / 2)
		else:
			count += 2
			get_min(a, (b + 1) / 2)
	else:
		count += int(a - b)
		get_min(b, b)
get_min(a, b)
print(count)


import math

def twoButtons():
	input1 = input().split()
	(n, m) = (int(input1[0]), int(input1[1]))
	pushButton = 0
	stop = 0
	if n > m:
		print(abs(m - n))
		return
	else:
		while n != m and stop < 100000:
			if m < n or m % 2 == 1:
				m += 1
			else:
				m /= 2
			pushButton += 1
			stop += 1
		if stop == 100000:
			print('Timeout')
			return
	print(pushButton)
twoButtons()


from collections import deque
(n, m) = map(int, input().split())
Q = deque()
Q.append((n, 0))
done = set()
r = -1
while len(Q) > 0:
	l = Q.popleft()
	if l[0] == m:
		r = l[1]
		break
	if (l[0], 'b') not in done and l[0] > 0:
		done.add((l[0], 'b'))
		Q.append((l[0] - 1, l[1] + 1))
	if (l[0], 'r') not in done and l[0] <= m:
		done.add((l[0], 'r'))
		Q.append((l[0] * 2, l[1] + 1))
print(r)


(target, source) = map(int, input().split())
steps = 0
while source is not target:
	if source == target:
		break
	elif source % 2 == 1 or source < target:
		steps += 1
		source += 1
	elif source > target:
		steps += 1
		source /= 2
	else:
		print('error')
print(steps)


I0 = lambda : map(int, input().split())
I1 = lambda : int(input())
I2 = lambda : list(map(int, input().split()))
from math import log2, ceil
(n, m) = I0()
if m >= n:
	res = 0
	while m >= n and n != m:
		if m % 2 == 0:
			m //= 2
		else:
			m += 1
		res += 1
	if m < n:
		res += n - m
	print(res)
else:
	print(n - m)


(x, y) = map(int, input().split())
if x > y:
	print(x - y)
else:
	c = 0
	while y > x:
		if y % 2 == 0:
			y = y // 2
			c += 1
		else:
			y = y + 1
			c += 1
	print(c + (x - y))


(n, m) = [int(p) for p in input().split()]
sum = 0
if n >= m:
	sum += n - m
else:
	sum = 0
	while m > n:
		if m % 2 == 0:
			sum += 1
			m = m // 2
		elif m % 2 == 1:
			sum += 2
			m = (m + 1) // 2
	sum += n - m
print(sum)


from collections import Counter, defaultdict, deque
tt = 1
for test in range(tt):
	vis = set()
	(n, m) = [int(x) for x in input().split()]
	q = deque([n])
	if n == m:
		print(0)
		exit()
	lvl = 1
	while True:
		for i in range(len(q)):
			nxt = q.popleft()
			vis.add(nxt)
			a = 2 * nxt
			b = nxt - 1
			if a == m or b == m:
				print(lvl)
				exit()
			if a <= 2 * m and a not in vis:
				q.append(a)
			if b > 0 and b not in vis:
				q.append(b)
		lvl += 1


(a, b) = input().split()
a = int(a)
b = int(b)
if b < a:
	print(a - b)
else:
	x = a
	y = b
	i = 0
	while x < y:
		x = 2 * x
		i = i + 1
	i = i + x - y
	j = 0
	while b > a:
		if b % 2 != 0:
			b = b + 1
			j = j + 1
		b = b / 2
		j = j + 1
	j = j + a - b
	m = min(i, j)
	print(int(m))


input = input().split()
start = int(input[0])
goal = int(input[1])
if goal == start:
	print(0)
list = []
list.append(start)
found = False
i = 0
done = [False] * 20000
iter = 0
while not found:
	end = len(list)
	if goal in list[i:end]:
		print(iter)
		found = True
	for j in range(i, end):
		if list[j] * 2 < len(done):
			if done[list[j] * 2] == False:
				list.append(list[j] * 2)
				done[list[j] * 2] = True
		if list[j] != 1:
			if done[list[j] - 1] == False:
				list.append(list[j] - 1)
				done[list[j] - 1] = True
	iter += 1
	i = end
quit()


(x, y) = [int(i) for i in input().split()]
k = 0
while x != y:
	k += 1
	if y % 2 == 0 and y > x:
		y = y // 2
	else:
		y += 1
print(k)


(n, m) = map(int, input().split())
result = 0
while n < m:
	result += 1 + m % 2
	m = (m + m % 2) / 2
result += n - m
print(int(result))


def get_int_list():
	from sys import stdin
	return [int(x) for x in stdin.readline().replace('\n', '').split(' ')]
(n, m) = get_int_list()
count = 0
while n != m:
	if m > n:
		if m % 2 == 0:
			m = m / 2
			count += 1
		else:
			m += 1
			count += 1
	elif n > m:
		m += 1
		count += 1
print(count)


def minpath(n, m, visited, q, d):
	while len(q) != 0:
		x = q.pop(0)
		visited[x] = True
		a = x * 2
		if x != 1:
			b = x - 1
		else:
			b = a
		if a in visited:
			d[a] = min(d[a], d[x] + 1)
		else:
			if a <= 10 ** 4:
				q.append(a)
			d[a] = d[x] + 1
			visited[a] = True
		if b in visited:
			d[b] = min(d[b], d[x] + 1)
		else:
			if b <= 10 ** 4:
				q.append(b)
			d[b] = d[x] + 1
			visited[b] = True
		if m in visited:
			return d[m]
(n, m) = list(map(int, input().split()))
visited = {}
d = {}
q = []
if m <= n:
	print(n - m)
else:
	q.append(n)
	d[n] = 0
	print(minpath(n, m, visited, q, d))


def get_min_operations(n, m):
	if m == n:
		return 0
	if m < n:
		return n - m
	cnt = 0
	while m >= n:
		if m == n:
			return cnt
		if m % 2 != 0:
			cnt += 1
			m += 1
		else:
			if m / 2 < n:
				return cnt + 1 + n - int(m / 2)
			cnt += 1
			m /= 2
	return cnt
(n, m) = map(int, input().split())
print(get_min_operations(n, m))


def main():
	a = list(map(int, input().split(' ')))
	(n, m) = (a[0], a[1])
	if n >= m:
		print(n - m)
	else:
		d = [1000000000000.0] * (2 * m)
		d[n] = 0
		Q = [n]
		while Q:
			e = Q[0]
			del Q[0]
			if e < m and d[2 * e] >= 1000000000000.0:
				Q.append(2 * e)
				d[2 * e] = d[e] + 1
			if e - 1 > 0 and d[e - 1] >= 1000000000000.0:
				Q.append(e - 1)
				d[e - 1] = d[e] + 1
		print(d[m])
while True:
	try:
		main()
	except:
		break


x = input()
(n, m) = x.strip().split(' ')
(n, m) = (int(n), int(m))
LIM = 10 ** 4 + 100
st = [None] * (LIM + 1)
st[n] = 0
delam = [n]
while len(delam) > 0:
	nov = set()
	for x in delam:
		for k in (2 * x, x - 1):
			if 0 <= k < LIM:
				if st[k] is None:
					nov.add(k)
					st[k] = st[x] + 1
				elif st[x] + 1 < st[k]:
					nov.add(k)
					st[k] = st[x] + 1
	delam = nov
print(st[m])


from collections import deque
import sys
(n, m) = map(int, input().split())
q = deque([(0, n)])
visit = [0] * 20001
visit[n] = 1
while q:
	(dist, curr) = q.popleft()
	if curr == m:
		print(dist)
		sys.exit()
	if curr < m and (not visit[2 * curr]):
		visit[2 * curr] = 1
		q.append((dist + 1, 2 * curr))
	if curr > 1 and (not visit[curr - 1]):
		visit[curr - 1] = 1
		q.append((dist + 1, curr - 1))


(n, m) = [int(x) for x in input().split()]
if n >= m:
	print(n - m)
else:
	s = 0
	while n != m:
		if m < n:
			m = m + 1
		elif m % 2 == 1:
			m = m + 1
		else:
			m = m // 2
		s = s + 1
	print(s)


def count(x, y, res):
	if x >= y:
		return x - y + res
	elif y % 2:
		return count(x, (y + 1) // 2, res + 2)
	else:
		return count(x, y // 2, res + 1)
s = input().split()
(x, y) = s
print(count(int(x), int(y), 0))


def knopki(n, m):
	if n == m:
		return '0'
	elif n > m:
		return n - m
	else:
		k = 0
		while n < m:
			if m % 2 == 0:
				m //= 2
			else:
				m += 1
			k += 1
		k += n - m
		return k
(x, y) = [int(i) for i in input().split()]
print(knopki(x, y))


def nrstDouble(n, m):
	i = 0
	while n < m:
		n *= 2
		i += 1
	return i
(n, m) = map(int, input().split())
ans = 0
while 1:
	if m <= n:
		ans += n - m
		break
	i = nrstDouble(n, m)
	val = (n * 2 ** i - m) // 2 ** i
	if val == 0:
		n *= 2
		ans += 1
	else:
		n -= val
		ans += val
print(ans)


from queue import Queue
from sys import stdin

def test_case(n, m):
	s = set()
	s.add(n)
	q = Queue()
	q.put((n, 0))
	while q:
		(u, w) = q.get()
		if u == m:
			print(w)
			return True
		if u < m:
			r = u * 2
			if r not in s:
				s.add(r)
				q.put((r, w + 1))
		if u > 0:
			b = u - 1
			if b not in s:
				s.add(b)
				q.put((b, w + 1))
	return False

def main():
	for s in stdin:
		test_case(*[int(v) for v in s.split()])
main()


(n, m) = str(input()).split()
n = int(n)
m = int(m)
num = 0
while n != m:
	if n > m:
		num += n - m
		n = m
	else:
		if m % 2 == 1:
			m += 1
			num += 1
		m //= 2
		num += 1
print(num)


(n, m) = [int(s) for s in input().split()]
MAX_LIMIT = 10000

def get_min_clicks():
	(inputs, clicks) = ({n}, 0)
	while True:
		new_inputs = set()
		for element in inputs:
			if element == m:
				return clicks
			if element > 0:
				new_inputs.add(element - 1)
			if element < m:
				new_inputs.add(element * 2)
		under_target = [el for el in new_inputs if el < m]
		over_target = [el for el in new_inputs if el >= m]
		if len(over_target) > 1:
			over_target = [min(over_target)]
		inputs = set()
		inputs = inputs.union(under_target).union(over_target)
		clicks += 1
print(get_min_clicks())


from queue import Queue
var = input().split(' ')
n = int(var[0])
m = int(var[1])
MAX = 10001
graph = [[] for i in range(MAX)]
used = [False for i in range(MAX)]
distances = [0 for i in range(MAX)]
for i in range(1, MAX):
	graph[i].append(i - 1)
	if i * 2 <= MAX:
		graph[i].append(i * 2)
queue = Queue()
queue.put(n)
used[n] = True
while not queue.empty():
	v = queue.get()
	for i in graph[v]:
		if not used[i]:
			queue.put(i)
			used[i] = True
			distances[i] = distances[v] + 1
print(distances[m])


(n, m) = [int(x) for x in input().split()]
count = 0
while n != m:
	if n > m:
		n -= 1
		count += 1
	elif m > n:
		if m % 2 == 0:
			m = m // 2
			count += 1
		elif m % 2 == 1:
			m = m + 1
			count += 1
print(count)


from collections import deque
(n, m) = map(int, input().strip().split(' '))
V = [False] * (20 ** 4 + 1)
T = deque([(n, 0)])
while len(T):
	t = T.popleft()
	if t[0] == m:
		print(t[1])
		quit()
	V[t[0]] = True
	left = (t[0] - 1, t[1] + 1)
	right = (t[0] << 1, t[1] + 1)
	if left[0] >= 0 and (not V[left[0]]):
		T.append(left)
	if t[0] < m and (not V[right[0]]):
		T.append(right)


rin = lambda : map(int, input().split())

def solve(n, m):
	if m < n:
		return n - m
	counter = 0
	while True:
		next_m = m // 2 if m % 2 == 0 else (m + 1) // 2
		if next_m <= n:
			return min(n - next_m + 1 + m % 2 + counter, counter + (2 * n - m) + 1)
		else:
			counter += 2 if m % 2 else 1
			m = m // 2 if m % 2 == 0 else (m + 1) // 2
(m, n) = rin()
print(solve(m, n))


__author__ = 'k0t'
(n, m) = map(int, input().split())
a = 0
while n != m:
	a += 1
	m += 1 if m < n or m & 1 else -m // 2
print(a)


def find_presses(n, m):
	presses = 0
	while n < m:
		if m % 2 == 0:
			m //= 2
		else:
			m += 1
		presses += 1
	print(presses + (n - m))
(n, m) = map(int, input().split(' '))
find_presses(n, m)


from sys import stdin

def main():
	(n, m) = stdin.readline().split(' ')
	print(solve(int(n), int(m)))

class Node:

	def __init__(self, data, depth=0, l=None, r=None):
		self.data = data
		self.depth = depth
		self.left = l
		self.right = r

def solve(n, m):
	queue = []
	seen = set()
	queue.append(Node(n))
	while len(queue) >= 0:
		temp = queue.pop(0)
		if temp.data == m:
			return temp.depth
		timesTwo = temp.data * 2
		if timesTwo not in seen and temp.data < m:
			temp.left = Node(timesTwo, temp.depth + 1)
			queue.append(temp.left)
			seen.add(timesTwo)
		minusOne = temp.data - 1
		if minusOne not in seen and minusOne >= 0:
			temp.right = Node(minusOne, temp.depth + 1)
			queue.append(temp.right)
			seen.add(minusOne)
main()


from sys import stdin, stdout
import math, sys, heapq
from itertools import permutations, combinations
from collections import defaultdict, deque, OrderedDict
from os import path
import random
import bisect as bi

def yes():
	print('YES')

def no():
	print('NO')
if path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

	def I():
		return int(input())

	def In():
		return map(int, input().split())
else:

	def I():
		return int(stdin.readline())

	def In():
		return map(int, stdin.readline().split())

def dict(a):
	d = {}
	for x in a:
		if d.get(x, -1) != -1:
			d[x] += 1
		else:
			d[x] = 1
	return d

def find_gt(a, x):
	i = bi.bisect_left(a, x)
	if i != len(a):
		return i
	else:
		return -1

def main():
	try:
		(n, m) = In()
		if m < n:
			print(n - m)
			return
		ans = 100000000.0
		for i in range(n // 2 + 1, n + 1):
			dp = [-1 for x in range(2 * m)]
			x = 0
			for j in range(n, n // 2, -1):
				dp[j] = x
				x += 1
			for j in range(n // 2 + 1, m):
				x = 1
				for k in range(j * 2, j, -1):
					if dp[k] == -1:
						dp[k] = dp[j] + x
						x += 1
					else:
						break
			ans = min(dp[m], ans)
		print(ans)
	except:
		pass
M = 998244353
P = 1000000007
for _ in range(1):
	main()


def two_buttons(n, m):
	d = {n: 0}
	keys = {n}
	while True:
		new_keys = set()
		for k in keys:
			if 2 * k <= 10000 and 2 * k not in d:
				d[2 * k] = d[k] + 1
				new_keys.add(2 * k)
			if k >= 1 and k - 1 not in d:
				d[k - 1] = d[k] + 1
				new_keys.add(k - 1)
		if m in d:
			return d[m]
		keys = new_keys

def main():
	(n, m) = map(int, input().split())
	ans = two_buttons(n, m)
	print(ans)
main()


from collections import deque as dq
from math import ceil
(n, m) = map(int, input().split())
if n >= m:
	res = n - m
	print(res)
else:
	q = dq([(n, 0)])
	s = 0
	vis = [0] * 100000
	while q:
		(a, s) = q.pop()
		vis[a] = 1
		if a == m:
			break
		if a - 1 > 0 and vis[a - 1] == 0:
			q.appendleft((a - 1, s + 1))
		if a <= m and vis[2 * a] == 0:
			q.appendleft((a * 2, s + 1))
	print(s)


(n, m) = [int(k) for k in input().split()]
cnt = 0
while n != m:
	if m > n:
		if m % 2 == 0:
			m = m // 2
			cnt += 1
		else:
			m += 1
			cnt += 1
	else:
		cnt += n - m
		n = m
print(cnt)


(n, m) = map(int, input().split())
if n > m:
	print(n - m)
else:
	q = [n]
	i = 0
	steps = {n: 0}
	run = True
	while i < len(q) and run:
		v = q[i]
		i += 1
		nxt = []
		if v > 1:
			nxt.append(v - 1)
		if v < m:
			nxt.append(v * 2)
		for u in nxt:
			if u > 0 and u not in steps:
				q.append(u)
				steps[u] = steps[v] + 1
				if u == m:
					run = False
					break
	print(steps[m])


(n, m) = map(int, input().split())
if n > m:
	print(n - m)
else:
	if m % 2 == 1:
		m += 1
		r = 1
	else:
		r = 0
	(nn, mm, mini) = (n, m, 0)
	a = [m]
	mini = 1000000
	while a[-1] != 1:
		if mm % 2 == 1:
			mm += 1
		l = mm // 2
		a.append(l)
		mm = mm // 2
	for i in range(len(a) - 1, -1, -1):
		if a[i] <= n:
			k = a[i]
		else:
			break
		i += 1
	r += n - k
	while k != m:
		k *= 2
		r += 1
		if k not in a:
			k -= 1
			r += 1
	print(r)


import queue

def foo(n, m):
	if n >= m:
		return n - m
	else:
		mx = 20002
		dist = [-1] * mx
		dist[n] = 0
		q = queue.Queue(maxsize=mx)
		q.put(n)
		while not q.empty():
			f = q.get()
			g = f * 2
			if g < mx and dist[g] == -1:
				dist[g] = dist[f] + 1
				q.put(g)
				if g == m:
					break
			l = f - 1
			if l > 0 and dist[l] == -1:
				dist[l] = dist[f] + 1
				q.put(l)
				if l == m:
					break
		return dist[m]
(n, m) = map(int, input().strip().split())
result = foo(n, m)
print(result)


from queue import Queue
(n, m) = [int(_) for _ in input().split()]
A = [-1] * (max(m, n) * 2 + 1)
Q = Queue()
Q.put((n, 0))
while not Q.empty():
	(a, s) = Q.get()
	if A[a] != -1:
		continue
	if a == m:
		print(s)
		exit()
	A[a] = s
	if a > 1:
		Q.put((a - 1, s + 1))
	if a * 2 < len(A):
		Q.put((a * 2, s + 1))


from collections import deque
(n, m) = (int(x) for x in input().split())
d = {}
q = deque()
d[n] = 0
q.append(n)
while m not in d:
	x = q.popleft()
	if x - 1 not in d:
		d[x - 1] = d[x] + 1
		q.append(x - 1)
	if x <= m * 2 and x * 2 not in d:
		d[x * 2] = d[x] + 1
		q.append(x * 2)
print(d[m])


(n, m) = map(int, input().split())
ans = 0
while n != m:
	while n > m:
		m += 1
		ans += 1
	if m % 2 == 0 and n != m:
		m //= 2
		ans += 1
	elif n != m and m % 2:
		m += 1
		m //= 2
		ans += 2
print(ans)


def fun(n, m):
	ans = 0
	ans = n * (m // n)
	print(n, m, '---')
	if m % 2 == 0:
		ans += n - m // 2 + 1
	else:
		ans += n - m // 2 + 2
	return ans

def bfs(n, m):
	temp = [(n, 0)]
	ans = 0
	visited = set()
	count = 0
	while temp:
		(node, count) = temp.pop(0)
		if node in visited or node <= 0 or node > 10000:
			continue
		visited.add(node)
		if node == m:
			return count
		if node - 1 not in visited:
			temp.append((node - 1, count + 1))
		if node * 2 not in visited:
			temp.append((node * 2, count + 1))
(n, m) = list(map(int, input().split()))
if m < n:
	print(n - m)
else:
	print(bfs(n, m))


import sys
(n, m) = map(int, input().split())
a = set([n])
i = 0
while True:
	i += 1
	b = set()
	for cur in a:
		b1 = cur * 2
		b2 = cur - 1
		if b1 == m or b2 == m:
			print(i)
			sys.exit()
		if cur < m:
			b.add(b1)
		if b2 > 0:
			b.add(b2)
	a = b


(n, m) = map(int, input().split())
(t, q) = (n, 0)
while t < m:
	t *= 2
	q += 1
q += t - m
stack = [[n, 0]]
mn = q
visited = [False] * 20000
while stack:
	cur = stack.pop(0)
	if cur[1] < q:
		if cur[0] * 2 == m or cur[0] - 1 == m:
			if cur[1] + 1 < mn:
				mn = cur[1] + 1
			continue
		if cur[0] - 1 > 0 and (not visited[cur[0] - 1]):
			visited[cur[0] - 1] = True
			stack.append([cur[0] - 1, cur[1] + 1])
		if cur[0] * 2 < 20000 and (not visited[cur[0] * 2]):
			visited[cur[0] * 2] = True
			if cur[0] < m:
				stack.append([cur[0] * 2, cur[1] + 1])
			elif cur[1] + cur[0] - m < mn:
				mn = cur[1] + cur[0] - m
print(mn)


def min_count(a, b):
	if a == b:
		return 0
	if a > b:
		return a - b
	count = 0
	while b > a:
		if b % 2 == 1:
			b += 1
			count += 1
		b /= 2
		count += 1
	count += a - b
	return count

def main():
	(a, b) = map(int, input().split())
	print(int(min_count(a, b)))
main()


import sys
import math
BESTCOUNT = sys.maxsize

def buttons(n, m, steps=0):
	global BESTCOUNT
	if n < 1 or (steps and steps > BESTCOUNT):
		return
	if n > m:
		BESTCOUNT = min(steps + n - m, BESTCOUNT)
	elif n == m:
		BESTCOUNT = min(steps, BESTCOUNT)
	else:
		buttons(n * 2, m, steps + 1)
		buttons(n - 1, m, steps + 1)
input_nums = input().strip().split(' ')
(n, m) = list(map(int, input_nums))
times = int(math.ceil(math.log(m / n) / math.log(2)))
helios = m
iterations = 0
while helios > n:
	if helios % 2 == 1:
		helios += 1
		iterations += 1
	helios /= 2
	iterations += 1
if n < m:
	BESTCOUNT = min(times + n * 2 ** times % m, int(iterations) + n - int(helios))
else:
	BESTCOUNT = n - m
print(BESTCOUNT)


import queue
visitados = [False for c in range(10 ** 4 + 1)]
parents = {}

def bfs(no_raiz):
	visitados[no_raiz] = True
	q = queue.Queue()
	q.put(no_raiz)
	while q.empty() == False:
		node = q.get()
		a = 0
		b = 0
		if node * 2 <= n * 2 and node * 2 <= 10 ** 4:
			if visitados[node * 2] == False:
				a = node * 2
				visitados[a] = True
				q.put(a)
			parents[a] = node
		if node - 1 > 0:
			if visitados[node - 1] == False:
				b = node - 1
				visitados[b] = True
				q.put(b)
				parents[b] = node
(m, n) = map(int, input().split())
bfs(m)
if m != n:
	chefe = n
	count = 0
	while True:
		chefe = parents[chefe]
		count += 1
		if chefe == m:
			break
	print(count)
else:
	print(0)


(n, m) = map(int, input().strip().split(' '))
if n > m:
	print(n - m)
else:
	verge = {}
	path = [-1] * 2 * m
	pick = []
	for i in range(1, 2 * m + 1):
		temp = []
		if i > 1:
			temp.append(i - 1)
		if i <= m:
			temp.append(2 * i)
		verge[i] = temp
	path[n] = 0
	pick.append(n)
	while path[m] == -1:
		cur = pick.pop(0)
		for j in verge[cur]:
			if path[j] == -1:
				path[j] = path[cur] + 1
				pick.append(j)
	print(path[m])


import math
from collections import defaultdict, Counter, deque
INF = float('inf')

def gcd(a, b):
	while b:
		(a, b) = (b, a % b)
	return a

def isPrime(n):
	if n <= 1:
		return False
	i = 2
	while i ** 2 <= n:
		if n % i == 0:
			return False
		i += 1
	return True

def primeFactor(n):
	if n % 2 == 0:
		return 2
	i = 3
	while i ** 2 <= n:
		if n % i == 0:
			return i
		i += 1
	return n

def vars():
	return map(int, input().split())

def array():
	return list(map(int, input().split()))

def can(m, s):
	if 0 <= s <= m * 9:
		return True
	return False

def main():
	(n, m) = vars()
	cnt = 0
	while n < m:
		if m % 2 == 0:
			m //= 2
		else:
			m += 1
		cnt += 1
	print(cnt + n - m)
t = 1
for _ in range(t):
	main()


from copy import deepcopy
import time

class Value:
	value = 0
	steps = 0
in1 = input()
arr1 = in1.split(' ')
start = int(arr1[0])
fin = int(arr1[1])
val = Value()
val.value = start
val.steps = 0
queue = []
queue.append(val)
done = pow(10, 5)
boo = []
for i in range(pow(10, 5)):
	boo.append(0)
while len(queue) != 0 and queue[0].value != fin:
	curr = queue.pop(0)
	if curr.value > pow(10, 4) + 1:
		continue
	if boo[curr.value] == 1:
		continue
	boo[curr.value] = 1
	if curr.value < 1:
		continue
	elif curr.value > fin:
		curr.steps += curr.value - fin
		curr.value -= fin
		if curr.steps < done:
			done = curr.steps
		continue
	else:
		sub = Value()
		sub.value = curr.value
		sub.steps = curr.steps
		sub.value -= 1
		sub.steps += 1
		queue.append(sub)
		double = Value()
		double.value = curr.value
		double.steps = curr.steps
		double.value *= 2
		double.steps += 1
		queue.append(double)
if len(queue) == 0:
	print(done)
elif queue[0].steps < done:
	print(queue[0].steps)
else:
	print(done)


class Node(object):

	def __init__(self, val, level):
		self.val = val
		self.level = level

def solve(m, n):
	if m >= n:
		return m - n
	queue = [Node(m, 0)]
	visited = set([m])
	count = 0
	while queue:
		item = queue.pop(0)
		if item.val == n:
			return item.level
		if item.val - 1 >= 0 and item.val - 1 not in visited:
			visited.add(item.val - 1)
			queue.append(Node(item.val - 1, item.level + 1))
		if item.val < n and item.val * 2 not in visited:
			visited.add(item.val * 2)
			queue.append(Node(item.val * 2, item.level + 1))
(n, m) = [int(val) for val in input().split(' ')]
print(solve(n, m))


import sys
import math
input = sys.stdin.readline
(n, m) = map(int, input().split())
mn = 10 ** 9
if n >= m:
	print(n - m)
else:
	d = [-1] * (2 * m + 1)
	d[n] = 0
	b = [n]
	i = 0
	for i in b:
		if i == m:
			break
		if d[i - 1] == -1 and i - 1 > 0:
			d[i - 1] = d[i] + 1
			b.append(i - 1)
		if i <= m:
			d[i * 2] = d[i] + 1
			b.append(i * 2)
	print(d[m])

def rec(d, i):
	if d[i - 1] == -1:
		d[i - 1] = d[i] + 1
	if d[i // 2] == -1 and i // 2 != 0:
		d[i // 2] = d[i] + 1


from collections import deque
(start_vertex, end_vertex) = map(int, input().split())
if end_vertex < start_vertex:
	print(start_vertex - end_vertex)
else:
	distances = [None] * (2 * end_vertex + 1)
	distances[start_vertex] = 0
	queue = deque([start_vertex])
	d = -1
	while queue:
		u = queue.popleft()
		if u < end_vertex:
			(a, b) = (u - 1, u * 2)
			if a > 0 and distances[a] is None:
				distances[a] = distances[u] + 1
				queue.append(a)
			if distances[b] is None:
				distances[b] = distances[u] + 1
				if b == end_vertex:
					break
				queue.append(b)
		elif u > end_vertex:
			a = u - 1
			if distances[a] is None:
				distances[a] = distances[u] + 1
				if a == end_vertex:
					break
				queue.append(a)
	print(distances[end_vertex])


(n, m) = [int(x) for x in input().split(' ')]
if n >= m:
	print(n - m)
else:
	count = 0
	while True:
		if m <= n:
			count += n - m
			break
		if m % 2 == 1:
			m += 1
			count += 1
		m //= 2
		count += 1
	print(count)


from sys import stdin
inp = list(map(lambda s: s.strip(), stdin.readlines()))
(n, m) = map(lambda x: int(x), inp[0].split())

def solve(n, m):
	if m < n:
		return n - m
	if m == n:
		return 0
	if m % 2 == 1:
		return 2 + solve(n, m // 2 + 1)
	return 1 + solve(n, m // 2)
print(solve(n, m))


def isPair(x):
	return not x % 2
(start, target) = map(int, input().split())
ans = 0
while start != target:
	ans += 1
	if start < target and isPair(target):
		target /= 2
	else:
		target += 1
print(ans)


queue = []
(first, second) = list(map(int, input().split(' ')))
queue.append([first, 0])
pos_mem = [False] * 100005
while queue:
	e = queue.pop(0)
	if pos_mem[e[0]] or e[0] > 10000 or e[0] < 1:
		continue
	else:
		pos_mem[e[0]] = True
	if e[0] - 1 == second:
		print(e[1] + 1)
		break
	else:
		queue.append([e[0] - 1, e[1] + 1])
	if e[0] * 2 == second:
		print(e[1] + 1)
		break
	else:
		queue.append([e[0] * 2, e[1] + 1])


import queue

def bfs(grafo, item, no):
	q = queue.SimpleQueue()
	vis = [False] * (10000 + 1)
	dist = [-1] * (10000 + 1)
	q.put(no)
	vis[no] = True
	dist[no] = 0
	while not q.empty():
		top = q.get()
		for vizinho in grafo[top]:
			if not vis[vizinho]:
				vis[vizinho] = True
				dist[vizinho] = dist[top] + 1
				if vizinho == item:
					return dist[item]
				q.put(vizinho)
	return dist[item]
(n, m) = map(int, input().split())
if n >= m:
	print(n - m)
elif n > 5000:
	if m % 2 == 0:
		num = n - m // 2 + 1
	else:
		num = n - (m // 2 + 1) + 2
	print(min(2 * n - m, num))
else:
	g = [(0,), (2,)]
	for i in range(2, 10000 + 1):
		if i * 2 <= 10000:
			g.append((i - 1, 2 * i))
		else:
			g.append((i - 1,))
	print(bfs(g, m, n))


(n, m) = map(int, input().split())
if n > m:
	print(n - m)
	exit()
r = 0
while m != n:
	if m % 2 or m < n:
		r += 1
		m += 1
	else:
		r += 1
		m //= 2
print(r)


q = list(map(int, input().split()))
(n, m) = (q[0], q[1])
if n > m:
	print(n - m)
else:
	L = [n]
	q = 0
	a = m
	while n < a:
		if a % 2 == 0:
			a = a // 2
		else:
			a = a + 1
		q += 1
	print(n - a + q)


import sys
lst = [int(n) for n in sys.stdin.readline().split()]
x = lst[0]
y = lst[1]
steps = 0
while y != x:
	if y < x:
		steps += x - y
		break
	if y % 2 == 1:
		y += 1
	else:
		y /= 2
	steps += 1
print(int(steps))


(n, m) = map(int, input().split())
visit = [0] * (10 ** 6 + 1)
ls = []
ls.append((n, 0))
while len(ls):
	cur = list(ls.pop(0))
	if cur[0] == m:
		print(cur[1])
		break
	visit[cur[0]] = 1
	if cur[0] - 1 > 0 and visit[cur[0] - 1] == 0:
		ls.append((cur[0] - 1, cur[1] + 1))
	if cur[0] * 2 < 10 ** 5 and visit[cur[0] * 2] == 0:
		ls.append((cur[0] * 2, cur[1] + 1))


from math import log2
(n, m) = map(int, input().split())
a = 0
while n != m:
	a += 1
	m += 1 if m & 1 or m < n else -m // 2
print(a)


class Solution:

	def __init__(self):
		(self.n, self.m) = map(int, input().split())
		self.cnt = 0

	def solution(self):
		if self.n >= self.m:
			print(self.n - self.m)
		else:
			while self.m > self.n:
				if self.m % 2 == 0:
					self.m //= 2
				else:
					self.m += 1
				self.cnt += 1
			if self.m == self.n:
				print(self.cnt)
			else:
				print(self.cnt + self.n - self.m)

def main():
	ob = Solution()
	ob.solution()
main()


def count_presses(n, m):
	if n == m:
		return 0
	if n > m:
		return n - m
	if m % 2:
		return count_presses(n, m + 1) + 1
	return count_presses(n, m // 2) + 1
print(count_presses(*map(int, input().split())))


from collections import deque

class node:

	def __init__(self, v, i):
		self.value = v
		self.step = i
(inp1, q) = map(int, input().split())
a = node(inp1, 0)
box = deque()
box.append(a)
p = node(0, 0)
marked = [False] * 20001
while True:
	p = box.popleft()
	if marked[p.value]:
		continue
	elif p.value == q:
		print(p.step)
		break
	else:
		marked[p.value] = True
		if p.value > q:
			np = node(p.value - 1, p.step + 1)
			box.append(np)
		elif p.value < 1:
			marked[0] = True
			continue
		else:
			np = node(p.value - 1, p.step + 1)
			box.append(np)
			np = node(p.value * 2, p.step + 1)
			box.append(np)


import math
from collections import *
import sys
from functools import reduce

def get_ints():
	return map(int, input().strip().split())

def get_list():
	return list(get_ints())

def get_string():
	return list(input().strip().split())

def printxsp(*args):
	return print(*args, end='')

def printsp(*args):
	return print(*args, end=' ')
UGLYMOD = int(1000000000.0) + 7
SEXYMOD = 998244353
MAXN = int(100000.0)
(n, m) = get_ints()
ans = 0
while m != n:
	if m > n and (not m & 1):
		m >>= 1
	else:
		m += 1
	ans += 1
print(ans)


from collections import deque
line = input().split(' ')
N = int(line[0])
M = int(line[1])
q = deque([(N, 0)])

def r():
	cts = [-1] * (M * 2 if N < M else N + 1)
	while len(q) > 0:
		(n, ct) = q.pop()
		if n == M:
			return ct
		cts[n] = ct
		if n - 1 >= 0 and cts[n - 1] < 0:
			q.appendleft((n - 1, ct + 1))
		if n < M and cts[n * 2] < 0:
			q.appendleft((n * 2, ct + 1))
print(r())


a = [int(x) for x in input().split()]
start = a[0]
end = a[1]
counter = 0
total = start
while total < end:
	total *= 2
	counter += 1
diff = total - end
coeffs = []
coeff = 1
for i in range(0, counter + 1):
	coeffs.append(coeff)
	coeff *= 2
needed = []
for i in range(len(coeffs) - 1, -1, -1):
	needed.append(int(diff / coeffs[i]))
	diff -= needed[-1] * coeffs[i]
print(sum(needed) + counter)


(n, m) = list(map(int, input().split()))
if n >= m:
	print(n - m)
else:
	t = m
	s = 0
	while t != n:
		if t > n:
			if t % 2 == 0:
				t //= 2
			else:
				t += 1
		else:
			t += 1
		s += 1
	print(s)


from collections import deque

class QNode:

	def __init__(self, val, level, visited):
		self.val = val
		self.dist = level
		self.visited = visited

def two_buttons(display, dest):
	q = deque()
	q.append(QNode(display, 0, True))
	x = set()
	while len(q):
		cur = q.popleft()
		x.add(cur.val)
		if cur.val == dest:
			return cur.dist
		if not cur.val * 2 in x and cur.val < dest * 2:
			q.append(QNode(cur.val * 2, cur.dist + 1, False))
		if not cur.val - 1 in x and cur.val - 1 > 0:
			q.append(QNode(cur.val - 1, cur.dist + 1, False))

def main():
	FirstInput = input()
	FirstInput = [int(s) for s in FirstInput.split(' ')]
	Element = FirstInput[0]
	SecondEle = FirstInput[1]
	result = 0
	print(two_buttons(Element, SecondEle))
main()


def main():
	(n, m) = [int(x) for x in input().split()]
	used = [0 for x in range(1, 100001)]
	q = [n]
	count = 1
	if m == n:
		print(0)
		return
	elif m < n:
		print(n - m)
		return
	while True:
		newQ = []
		for x in q:
			if x - 1 == m or 2 * x == m:
				print(count)
				return
			if used[x - 1] == 0 and x - 1 > 0:
				newQ.append(x - 1)
				used[x - 1] = 1
			if 2 * x < 2 * m and used[2 * x] == 0:
				newQ.append(2 * x)
				used[2 * x] = 1
		q = newQ
		count += 1
main()


from collections import deque

def minClicks(n, m):
	nums = deque([(n, 0)])
	seen = set()
	upperBound = 0
	outOfRange = lambda x: x > upperBound and upperBound
	while nums[0][0] != m:
		num = nums.popleft()
		if num[0] in seen or outOfRange(num[0]):
			continue
		elif num[0] > m:
			upperBound = num[0]
		nums.append((num[0] - 1, num[1] + 1))
		nums.append((num[0] * 2, num[1] + 1))
		seen.add(num[0])
	return nums[0][1]
(N, M) = list(map(int, input().split()))
print(minClicks(N, M))


def extend(l):
	global n, door
	for i in l[:]:
		if done[i] == 0:
			if i < n and i > 0:
				if i * 2 not in l:
					l.append(i * 2)
				if i - 1 not in l:
					l.append(i - 1)
			elif i > 0:
				door = min(step + i - n, door)
		l.remove(i)
		done[i] = 1
	return l
(m, n) = map(int, input().split())
s = [m]
step = 0
door = 10000
done = [0] * max(m + 1, 2 * n + 1)
while n not in s:
	s = extend(s)
	step += 1
	if step > door:
		break
print(min(door, step))


(n, m) = map(int, input().split())
t = [1] * m
d = [(n, 0)]
x = n + m
while d:
	(n, s) = d.pop(0)
	if n >= m:
		x = min(x, s + n - m)
	elif t[n]:
		t[n] = 0
		d.append((2 * n, s + 1))
		if n > 1:
			d.append((n - 1, s + 1))
print(x)


from collections import defaultdict
(a, b) = [int(x) for x in input().split()]
level = {a: 0}
queue = [a]
visited = {}
visited = defaultdict(lambda : False, visited)
visited[a] = True
count = 0
while queue:
	if b in level:
		print(level[b])
		break
	parent = queue.pop(0)
	ele1 = parent - 1
	ele2 = parent * 2
	if ele1 > 0 and (not visited[ele1]):
		queue.append(ele1)
		level[ele1] = level[parent] + 1
		visited[ele1] = True
	if ele2 <= 20000 and (not visited[ele2]):
		queue.append(ele2)
		level[ele2] = level[parent] + 1
		visited[ele2] = True


def time(b, a):
	if b >= a:
		return b - a
	elif a % 2 == 1:
		return time(b, (a + 1) // 2) + 2
	else:
		return time(b, a // 2) + 1
(n, m) = map(int, input().split())
print(time(n, m))


import math
(n, m) = map(int, input().split(' '))
if m >= n:
	a = math.ceil(math.log2(m / n))
else:
	a = 0
b = pow(2, a) * n - m
c = 0
for i in range(a, -1, -1):
	c += b // pow(2, i)
	b %= pow(2, i)
print(c + a)


from sys import stdin, stdout
(n, m) = [int(x) for x in stdin.readline().split()]
if n >= m:
	print(f'{n - m}')
else:
	cnt = 0
	while m > n:
		if m % 2 == 0:
			m = m // 2
		else:
			m += 1
		cnt += 1
	cnt += n - m
	print(cnt)


def solve(n, m):
	if n >= m:
		return n - m
	if m % 2:
		return 1 + solve(n, m + 1)
	return 1 + solve(n, m // 2)
(n, m) = map(int, input().split())
print(solve(n, m))


def bfs(n, m):
	queue = [n]
	level = {}
	level[n] = 0
	if n > m:
		return n - m
	while queue:
		s = queue.pop(0)
		for a in [s * 2, s - 1]:
			if level.get(a) == None and a > 0 and (a < 2 * m):
				level[a] = level[s] + 1
				queue.append(a)
	return level.get(m)
(n, m) = map(int, input().split())
print(bfs(n, m))


inp = input()
chars = inp.split()
n = int(chars[0])
m = int(chars[1])
ans = 0
while n < m:
	if m % 2 == 1:
		m = m + 1
	else:
		m = m / 2
	ans = ans + 1
print(int(ans + n - m))


(a, b) = [int(i) for i in input().split(' ')]
if a >= b:
	print(a - b)
else:
	count = 0
	while b > a:
		if b % 2 == 0:
			b /= 2
		else:
			b += 1
		count += 1
	count += a - b
	print(int(count))


(a, b) = map(int, input().split())
if b > a:
	ans = 0
	while True:
		if b % 2 == 0:
			b /= 2
			ans += 1
		else:
			b += 1
			ans += 1
		if b == a:
			print(ans)
			break
		elif b < a:
			print(int(ans + a - b))
			break
else:
	print(a - b)


from queue import *
(n, m) = map(lambda i: int(i), input().split())
marked = [0] * 20001
searchqueue = Queue()
iters = 0
searchqueue.put([n, 0])
while not searchqueue.empty():
	(v, level) = searchqueue.get()
	if v == m:
		print(level)
		break
	marked[v] = 1
	if 2 * v <= 10000 and marked[2 * v] == 0:
		searchqueue.put([2 * v, level + 1])
	if v - 1 > 0 and marked[v - 1] == 0:
		searchqueue.put([v - 1, level + 1])


[n, m] = [int(_) for _ in input().split()]
ans = 0
if n > m:
	ans = n - m
else:
	lis = [-1 for _ in range(2 * m + 1)]
	count = 0
	lis[n] = count
	stepset = {n}
	while lis[m] == -1:
		count += 1
		tempset = set([])
		for x in stepset:
			y = 2 * x
			if 0 < y < 2 * m and lis[y] == -1:
				tempset.add(y)
				lis[y] = count
			y = x - 1
			if 0 < y < 2 * m and lis[y] == -1:
				tempset.add(y)
				lis[y] = count
		stepset = tempset
	ans = lis[m]
print(ans)


def f(n, m):
	count = 0
	while True:
		if m == n:
			return count
		elif m < n:
			return count + (n - m)
		elif m % 2 == 1:
			count += 1
			m += 1
		else:
			count += 1
			m = m // 2
(n, m) = map(int, input().split())
print(f(n, m))


from collections import deque, namedtuple
Pair = namedtuple('Pair', ['x', 'steps'])
(n, m) = map(int, input().split())
q = deque([Pair(n, 0)])
done = {n}
while q:
	cur = q.popleft()
	done.add(cur.x)
	if cur.x == m:
		print(cur.steps)
		break
	if cur.x - 1 > 0 and cur.x - 1 not in done:
		q.append(Pair(cur.x - 1, cur.steps + 1))
	if cur.x * 2 < m * 4 and cur.x * 2 not in done:
		q.append(Pair(cur.x * 2, cur.steps + 1))


(n, m) = [int(next) for next in input().split()]
if m <= n:
	print(n - m)
else:
	answer = 0
	while n < m:
		if m % 2 == 1:
			m += 1
			answer += 1
		m //= 2
		answer += 1
	if n == m:
		print(answer)
	else:
		print(answer + n - m)


import math
t = input()
loc = t.split(' ')
n = int(loc[0])
m = int(loc[1])
b = math.ceil(math.log2(m / n))
c = 0
temp = m
if m <= n:
	d = n - m
else:
	for i in range(1, b + 1):
		if temp % 2 == 0:
			temp = temp / 2
		else:
			c = c + 1
			temp = (temp + 1) / 2
	d = c + n - temp + b
print(int(d))


def bfs(d, s, e):
	que = []
	que.append(s)
	dist = {s: 0}
	flag = 0
	while que:
		f = que[0]
		que.pop(0)
		for i in d[f]:
			if i not in dist:
				que.append(i)
				dist[i] = dist[f] + 1
			if i == e:
				flag = 1
				break
		if flag == 1:
			break
	return dist[e]
(n, m) = map(int, input().split())
d = {}
v = [i for i in range(1, 2 * max(n, m) + 1)]
for i in v:
	if i == 1:
		d[i] = [2 * i]
	elif 2 * i > 2 * m:
		d[i] = [i - 1]
	else:
		d[i] = [i - 1, 2 * i]
print(bfs(d, n, m))


def bfs(u, m):
	N = 10 ** 5
	vis = [False] * N
	d = [10 ** 10] * N
	d[u] = 0
	q = []
	q.append(u)
	while q:
		v = q.pop(0)
		if v == m:
			return d[v]
		if v < 0:
			continue
		if vis[v] == False:
			vis[v] = True
			q.append(v - 1)
			d[v - 1] = d[v] + 1
			if v < m:
				q.append(2 * v)
				d[2 * v] = d[v] + 1
	return -1
(n, m) = list(map(int, input().split()))
if n > m:
	print(n - m)
else:
	k = bfs(n, m)
	print(k)


(n, m) = map(int, input().split())
lis = [[m, 0]]
length = 1
dp = [0 for i in range(100000)]
while True:
	if length == 0 or length == 200:
		break
	li = lis.pop()
	length -= 1
	a = li[0]
	b = li[1]
	if dp[a] == 1:
		continue
	dp[a] = 1
	if a == n:
		print(b)
		break
	if a // 2 == a / 2:
		l = [a // 2, b + 1]
		lis.insert(0, l)
		length += 1
	l = [a + 1, b + 1]
	lis.insert(0, l)
	length += 1


(n, m) = (int(i) for i in input().split())
ans = 0
while n < m:
	if m & 1:
		ans += 1
		m += 1
	m //= 2
	ans += 1
print(ans + n - m)


def sol(a, b):
	f = True
	c = 0
	r = []
	if b % 2:
		c += 1
		b += 1
	while b > 0 and (not b % 2):
		r = [b // 2] + r
		b //= 2
	if a < r[0]:
		return c + sol(a, r[0]) + sol(r[0], 2 * r[-1])
	else:
		for i in range(len(r)):
			if a == r[i]:
				c += len(r) - i
				f = False
				break
			elif a < r[i]:
				c += a - r[i - 1]
				c += len(r) - (i - 1)
				f = False
				break
		if f:
			c += a - r[-1]
			c += 1
		return c
(x, y) = map(int, input().split())
if y <= x:
	print(x - y)
else:
	print(sol(x, y))


(a, b) = map(int, input().split())
if b <= a:
	print(a - b)
else:
	k = int(0)
	while b != a:
		if b > a and b % 2 == 0:
			b = b / 2
		else:
			b = b + 1
		k = k + 1
	print(k)


(n, m) = tuple(input().split(' '))
n = int(n)
m = int(m)
resultado = 0
while m > n:
	mod_m = m % 2
	if mod_m == 1:
		m = m + 1
		resultado = resultado + 1
	else:
		m = m / 2
		resultado = resultado + 1
resultado = resultado + (n - m)
resultado = int(resultado)
print(resultado)


(start, target) = map(int, input().split())

def recur(s, t, steps):
	if s > t:
		return steps + s - t
	elif s == t:
		return steps
	elif t & 1:
		return recur(s, t + 1, steps + 1)
	else:
		return recur(s, t // 2, steps + 1)
print(recur(start, target, 0))


from collections import deque

def BFS(start, target):
	visited = [False] * (max(start, target) * 2 + 1)
	visited[start] = False
	queue = deque()
	queue.append((start, 0))
	while True:
		(n, d) = queue.popleft()
		if n % 2 == 0:
			if n // 2 == target:
				return d + 1
			if not visited[n // 2]:
				queue.append((n // 2, d + 1))
				visited[n // 2] = True
		if n + 1 == target:
			return d + 1
		if not visited[n + 1]:
			queue.append((n + 1, d + 1))
			visited[n + 1] = True
x = reversed(list(map(int, input().split())))
print(BFS(*x))


(a, b) = list(map(int, input().split()))
if a > b:
	print(a - b)
else:
	c = 0
	while a < b:
		if a != b and b % 2 == 0:
			b = b // 2
			c += 1
		else:
			b += 1
			c += 1
	c = a - b + c
	print(c)


from math import log
(n, m) = map(int, input().split())
if m <= n:
	print(n - m)
else:
	s = 0
	while m > n:
		if m % 2 != 0:
			s += 2
		else:
			s += 1
		m = (m + m % 2) / 2
	if m != n:
		s += n - m
	print(int(s))


(src, dest) = [int(x) for x in str(input()).strip().split()]
num_steps = 0
if src >= dest:
	num_steps = src - dest
else:
	while dest > src:
		if dest % 2 == 1:
			dest += 1
		else:
			dest //= 2
		num_steps += 1
	num_steps += src - dest
print(num_steps)


import queue
(n, m) = [int(x) for x in input().split()]
if m <= n:
	print(n - m)
else:
	q = queue.Queue()
	used = [0] * 10001
	q.put((n, 0))
	used[n] = 1
	while True:
		qelem = q.get()
		if qelem[0] * 2 == m or qelem[0] - 1 == m:
			print(qelem[1] + 1)
			break
		if qelem[0] * 2 <= 10000 and used[qelem[0] * 2] == 0:
			q.put((qelem[0] * 2, qelem[1] + 1))
			used[qelem[0] * 2] = 1
		if qelem[0] - 1 > 0 and used[qelem[0] - 1] == 0:
			q.put((qelem[0] - 1, qelem[1] + 1))
			used[qelem[0] - 1] = 1


lst = [int(i) for i in input().split()]
n = lst[0]
m = lst[1]

class Node:

	def __init__(self, val):
		self.val = val
		self.adj = []
nodes = []
max_node = 2 * max(m, n) + 1
for i in range(0, (max_node - 1) * 2 + 2):
	nodes.append(Node(i))
if max_node > 1:
	nodes[1].adj.append(nodes[2])
for i in range(2, max_node):
	nodes[i].adj.append(nodes[i - 1])
	nodes[i].adj.append(nodes[2 * i])
visited = set()
queue = [(nodes[n], 0)]
path_len = 0
while len(queue) != 0:
	(node, path_len) = queue.pop(0)
	visited.add(node)
	if node.val == m:
		break
	for adj in node.adj:
		if adj not in visited:
			queue.append((adj, path_len + 1))
print(path_len)


def process_node(arr, visited, o_visited, rev):
	curr = arr.pop(0)
	if curr[0] in visited:
		return
	visited[curr[0]] = curr[1]
	if curr[0] in o_visited:
		print(o_visited[curr[0]] + visited[curr[0]])
		exit()
	if not rev:
		arr.append((curr[0] * 2, curr[1] + 1))
		arr.append((curr[0] - 1, curr[1] + 1))
	else:
		if curr[0] % 2 == 0:
			arr.append((curr[0] / 2, curr[1] + 1))
		arr.append((curr[0] + 1, curr[1] + 1))
(n, m) = map(int, input().split())
(arr, arr2) = ([], [])
arr.append((n, 0))
arr2.append((m, 0))
visited = {}
visited2 = {}
while True:
	process_node(arr, visited, visited2, False)
	process_node(arr2, visited2, visited, True)


def main():
	entrada = list(map(int, input().split()))
	n = entrada[0]
	m = entrada[1]
	if n == m:
		print(0)
	elif n >= m:
		print(n - m)
	else:
		contador = 0
		while m > n:
			if m % 2 == 0:
				m = m / 2
				contador += 1
			else:
				m = m + 1
				contador += 1
		while n != m:
			m = m + 1
			contador += 1
		print(contador)
main()


def main():
	from sys import stdout
	(n, m) = map(int, input().split())
	res = 0
	while n != m:
		if n >= m:
			res += n - m
			n = m
		else:
			if m % 2 == 1:
				m += 1
				res += 1
			m = m / 2
			res += 1
	stdout.write(str(int(res)))
main()


from sys import stdout
(n, m) = map(int, input().split())
if m <= n:
	print(n - m)
else:
	c = 0
	while m > n:
		if n == m:
			break
		if m % 2 != 0:
			m += 1
			c += 1
		else:
			m //= 2
			c += 1
	if m < n:
		c += n - m
	stdout.write(str(c))


(x, y) = list(map(int, input().split()))
a = 0
while x != y:
	a = a + 1
	if y < x or y & 1:
		y = y + 1
	else:
		y = y // 2
print(a)


(n, m) = map(int, input().split())
upar = [n]
niche = []
steps = 0
br = 0
dict = {n}
if n < m:
	while True:
		if br == 1:
			break
		for i in upar:
			if i > 0 and i < m * 2:
				if i - 1 not in dict:
					niche.append(i - 1)
					dict.add(i - 1)
					if niche[-1] == m:
						br = 1
						break
				if i * 2 not in dict:
					niche.append(i * 2)
					dict.add(i * 2)
					if niche[-1] == m:
						br = 1
						break
		upar = []
		steps += 1
		if br == 1:
			break
		for i in niche:
			if i > 0 and i < m * 2:
				if i - 1 not in dict:
					upar.append(i - 1)
					dict.add(i - 1)
					if upar[-1] == m:
						br = 1
						break
				if i * 2 not in dict:
					upar.append(i * 2)
					dict.add(i * 2)
					if upar[-1] == m:
						br = 1
						break
		niche = []
		steps += 1
else:
	steps = n - m
print(steps)


(n, m) = map(int, input().split())
ans = 0
if n >= m:
	print(n - m)
else:
	while n != m:
		if m < n:
			ans += n - m
			break
		elif m % 2 == 0:
			m = m // 2
			ans += 1
		else:
			m += 1
			ans += 1
			if n == m:
				break
			m = m // 2
			ans += 1
	print(ans)


(target, value) = map(int, input().split())
count = 0
while True:
	if value == target:
		break
	if value < target:
		value += 1
	elif value % 2 == 1:
		value += 1
	else:
		value = value // 2
	count += 1
print(count)


(n, m) = list(map(lambda x: int(x), input().split()))

def twoButtons(n, m):
	ans = 0
	while n != m:
		if m > n:
			ans += 1
			if m % 2 == 0:
				m /= 2
			else:
				m += 1
		elif m < n:
			m += 1
			ans += 1
	return ans
print(twoButtons(n, m))


from collections import deque
(n, m) = map(int, input().split())
queue = deque()
queue.append((m, 0))
seen = set()
while queue:
	(number, steps) = queue.popleft()
	if number == n:
		print(steps)
		break
	if number in seen:
		continue
	seen.add(number)
	if number % 2 == 0:
		queue.append((number // 2, steps + 1))
	queue.append((number + 1, steps + 1))


def f(n, m):
	if n >= m:
		return n - m
	if m % 2 == 0:
		return 1 + f(n, m // 2)
	else:
		return 1 + f(n, m + 1)
(a, b) = (int(x) for x in input().split())
print(f(a, b))


(a, b) = map(int, input().split())
z = 0
while a < b:
	if b % 2 == True:
		z += 1
		b += 1
	else:
		b = b // 2
		z += 1
print(str(int(abs(z + a - b))))


(a, b) = [int(x) for x in input().split()]
if a > b:
	print(a - b)
else:
	tot = 0
	while a < b:
		a *= 2
		tot += 1
	greatestPower = 2 ** tot
	remainder = (a - b) % greatestPower
	tot += (a - b) // greatestPower
	for i in bin(remainder)[2:]:
		if i == '1':
			tot += 1
	print(tot)


p = input().split()
a = int(p[0])
b = int(p[1])
if b <= a:
	print(a - b)
else:
	i = 0
	while a != b:
		while b % 2 == 0 and b > a:
			b = b // 2
			i = i + 1
		if b != a:
			b = b + 1
			i = i + 1
	print(i)


(curr, goal) = map(int, input().split())
if curr >= goal:
	print(curr - goal)
else:
	clicks = 0
	while goal != curr:
		if goal <= curr:
			clicks += curr - goal
			break
		clicks += 1 + goal % 2
		goal = (goal + 1) // 2
	print(clicks)


(n, m) = map(int, input().split())
p = 0
while m > n and m > 0:
	if m % 2 == 0:
		m //= 2
		p += 1
	else:
		m += 1
		p += 1
else:
	print(abs(m - n) + p)


inputs = input()
split = inputs.split(' ')
display = int(split[0])
goal = int(split[1])
visited = [display]
queue = [(display, 1)]

def main():
	while queue:
		(s, d) = queue.pop(0)
		neighbors = []
		if s > 0:
			neighbors.append(s - 1)
		if s <= goal:
			neighbors.append(s * 2)
		for neighbor in neighbors:
			if neighbor == goal:
				print(d)
				return
			if neighbor in visited:
				continue
			visited.append(neighbor)
			queue.append((neighbor, d + 1))
if display == goal:
	print(0)
else:
	main()


def solve(n, m):
	if n >= m:
		return n - m
	else:
		c = 0
		while n != m and n < m:
			if m % 2 == 0:
				m //= 2
			else:
				m += 1
			c += 1
		return c + (n - m)
(n, m) = map(int, input().split())
print(solve(n, m))


(nz, mz) = input().split()
n = int(nz)
m = int(mz)
c = 0
while m > n:
	if m % 2 == 0:
		m = m // 2
	else:
		m += 1
	c += 1
c += n - m
print(c)


def solve():
	(n, m) = map(int, input().split())
	result = 0
	while n != m:
		if m > n:
			if m % 2 == 0:
				m //= 2
				result += 1
			else:
				m += 1
				result += 1
		else:
			m += 1
			result += 1
	print(result)
solve()


def cal(n, m):
	if n >= m:
		return int(n - m)
	elif m % 2 == 0:
		return int(1 + cal(n, m / 2))
	else:
		return int(2 + cal(n, (m + 1) / 2))
(n, m) = map(int, input().split())
print(cal(n, m))


from collections import deque

def bfs(n, m):
	q = deque()
	q.append([n, 0])
	while q:
		(x, y) = q.popleft()
		if x == m:
			return y
		if visited[x]:
			continue
		if not visited[x]:
			visited[x] = True
			k1 = x - 1
			if k1 > 0:
				q.append([k1, y + 1])
			k2 = x * 2
			if k2 <= 2 * m:
				q.append([k2, y + 1])
(n, m) = map(int, input().split())
if n >= m:
	print(n - m)
	exit(0)
visited = [False] * (2 * m + 1)
r = bfs(n, m)
print(r)


(n, m) = input(' ').split()
n = int(n)
m = int(m)
(n, m) = (m, n)
n = n
m = m
count = 0
while n - m != 0:
	if n < m or n == m:
		count = count + m - n
		n = 0
		m = 0
		break
	elif n > m:
		if n % 2 == 0:
			n = n / 2
			count = count + 1
			m = m
		else:
			n = n + 1
			count = count + 1
			m = m
print(int(count))


from collections import deque
(n, m) = [int(i) for i in input().split()]
ans = [-1] * ((n + m) * 2 + 1)
ans[m] = 0
queue = deque([m])
while queue:
	k = queue.popleft()
	if ans[k + 1] == -1:
		ans[k + 1] = ans[k] + 1
		queue.append(k + 1)
	if not k % 2 and ans[k // 2] == -1:
		ans[k // 2] = ans[k] + 1
		queue.append(k // 2)
	if k == n:
		break
print(ans[k])


from collections import deque

def bfs(n, m):
	queue = deque()
	queue.append(n)
	visited = {n: 0}
	while queue:
		top = queue.popleft()
		if top < m and top * 2 not in visited and (top * 2 <= 100000):
			visited[top * 2] = visited[top] + 1
			queue.append(top * 2)
			if top * 2 == m:
				return visited[m]
		if top - 1 not in visited and top - 1 > 0:
			visited[top - 1] = visited[top] + 1
			queue.append(top - 1)
			if top - 1 == m:
				return visited[m]
(n, m) = map(int, input().split())
if n > m:
	print(n - m)
else:
	print(bfs(n, m))


(n, m) = list(map(int, input().split()))

def bouton(n, m):
	if n == m:
		return 0
	if n > m:
		return n - m
	if n <= 0 and m > 0:
		return n
	if m % 2 == 1:
		return 1 + bouton(n, m + 1)
	else:
		return 1 + bouton(n, m / 2)
print(int(bouton(n, m)))


import math

def main():
	(n, m) = map(int, input().split())
	i = 0
	while n != m:
		i += 1
		if m % 2 == 1 or m < n:
			m += 1
		else:
			m = m // 2
	print(i)
main()


(n, m) = (int(_) for _ in input().split())
count = 0
while m != n:
	if m > n and m % 2 == 0:
		m //= 2
	else:
		m += 1
	count += 1
print(count)


r = lambda : map(int, input().split())
(n, m) = r()

def func_exe(n, m):
	if n > m:
		return n - m
	elif m == n:
		return 0
	elif m % 2 == 0:
		return 1 + func_exe(n, int(m / 2))
	else:
		return 1 + func_exe(n, int(m + 1))
print(func_exe(n, m))


import queue
max_n = 10 ** 4 * 2 + 1

def bfs(n, m):
	D = [-1] * max_n
	D[n] = 0
	Q = queue.Queue()
	Q.put(n)
	while not Q.empty():
		u = Q.get()
		(x, y) = (u - 1, u * 2)
		if x < 0 or y > max_n:
			continue
		for i in [x, y]:
			if D[i] == -1:
				D[i] = D[u] + 1
				Q.put(i)
	return D[m]
(n, m) = map(int, input().split())
print(bfs(n, m))


from collections import deque

def main():
	(n, m) = map(int, input().split())
	vertex = [-1] * (max(n, m) * 2)
	queue = deque()
	queue.append(n)
	vertex[n] = 0
	while queue:
		pos = queue.popleft()
		red = pos * 2
		blue = pos - 1
		if m > n and red <= 2 * m and (vertex[red] == -1):
			queue.append(red)
			vertex[red] = vertex[pos] + 1
		if blue >= 0 and vertex[blue] == -1:
			queue.append(blue)
			vertex[blue] = vertex[pos] + 1
		if vertex[m] != -1:
			break
	print(vertex[m])
main()


import math, string, itertools, fractions, heapq, collections, re, array, bisect
from itertools import chain, dropwhile, permutations, combinations
from collections import defaultdict, deque

def VI():
	return list(map(int, input().split()))

def main2(n, m):
	if m == n:
		print(0)
		return
	if m <= n:
		print(n - m)
		return
	i = 0
	while n * 2 <= m + 1:
		n *= 2
		i += 1
	if m == n:
		print(i)
		return
	while n > (m + 1) // 2:
		n -= 1
		i += 1
	if n < m:
		n *= 2
		i += 1
	print(i + n - m)

def main(n, m):
	if m <= n:
		print(n - m)
		return
	nv = 2 * m + 1
	g = [[] for i in range(nv)]
	for i in range(nv - 1):
		g[i + 1].append(i)
	for i in range((nv + 1) // 2):
		g[i].append(i * 2)
	marked = [False] * nv
	q = deque()
	way = [None] * nv
	q.appendleft(n)
	marked[n] = True
	while len(q) != 0 and way[m] is None:
		v = q.pop()
		for e in g[v]:
			if not marked[e]:
				q.appendleft(e)
				marked[e] = True
				way[e] = v
	i = 0
	v = m
	while v != n:
		i += 1
		v = way[v]
	print(i)

def main_input(info=0):
	(n, m) = VI()
	main(n, m)
main_input()


import sys
from functools import lru_cache
(n, m) = [int(x) for x in input().split()]
res = 0
while n < m:
	res += 1
	if m % 2 == 0:
		m //= 2
	else:
		m += 1
res += n - m
print(res)


(n, m) = map(int, input().split())
cnt = 0
while n < m:
	if m & 1:
		m += 1
		cnt += 1
	else:
		m = m >> 1
		cnt += 1
cnt += n - m
print(cnt)


from sys import stdin

def solution(n, m):
	if n == m:
		print(0)
		return
	if n > m:
		print(n - m)
		return
	counter = 0
	while n != m:
		if m > n and m % 2 == 0:
			m /= 2
		else:
			m += 1
		counter += 1
	print(counter)
for line in stdin:
	testcases = list(map(int, line.split()))
	solution(testcases[0], testcases[1])


from collections import deque

def bfs(n, m):
	q = deque()
	q.append([n, 0])
	while q:
		(x, y) = q.popleft()
		if visited[x] == True:
			continue
		if x == m:
			print(y)
		visited[x] = True
		if 2 * x <= 2 * m:
			q.append([2 * x, y + 1])
		if x - 1 > 0:
			q.append([x - 1, y + 1])
(n, m) = map(int, input().split())
visited = [False] * (2 * m + 1)
if n >= m:
	print(n - m)
	exit(0)
res = bfs(n, m)


(n, m) = map(int, input().split())
contador = 0
if n > m:
	contador = n - m
	print(contador)
	quit()
while n != m:
	if m % 2 == 0 and n < m:
		m = m / 2
		contador += 1
	else:
		m += 1
		contador += 1
print(contador)


import queue
mx = 10 ** 4 * 2 + 1

def bfs(n, m):
	dist = [-1] * mx
	q = queue.Queue()
	dist[n] = 0
	q.put(n)
	while not q.empty():
		x = q.get()
		(a, b) = (x - 1, x * 2)
		if a < 0 or b > mx:
			continue
		for i in [a, b]:
			if dist[i] == -1:
				dist[i] = dist[x] + 1
				q.put(i)
	return dist[m]

def main():
	(n, m) = [int(z) for z in input().split()]
	print(bfs(n, m))
main()


def f():
	ans = 0
	(n, m) = map(int, input().split())
	while n != m:
		if n > m:
			ans += n - m
			break
		else:
			if m % 2 == 0:
				m /= 2
			else:
				m += 1
			ans += 1
	print(int(ans))
f()


(n, m) = map(int, input().split())
t = 0
if m > n:
	while n < m:
		if m % 2 == 1:
			m = m + 1
		elif m % 2 == 0:
			m = m / 2
		t = t + 1
if m < n:
	while n != m:
		m = m + 1
		t = t + 1
print(t)


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return [int(x) for x in sys.stdin.readline().split()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def main():
	(n, m) = LI()
	s = set()
	c = set([n])
	r = 0
	while 1:
		if m in c:
			return r
		s |= c
		d = set()
		for t in c:
			if t < m:
				d.add(t * 2)
			d.add(t - 1)
		d -= s
		c = d
		r += 1
	return -1
print(main())


import sys
sys.setrecursionlimit(10 ** 6)
debug_mode = True if len(sys.argv) > 1 and sys.argv[1] == '-d' else False
if debug_mode:
	import os
	infile = open(os.path.abspath(__file__).replace('.py', '.in'))

	def input():
		return infile.readline()
from collections import defaultdict, deque

def main():
	(n, m) = list(map(int, input().strip().split()))
	if m <= n:
		print(n - m)
		return
	(Q, S) = (deque([(n, 0)]), set())
	while Q:
		(curr, clicks) = Q.popleft()
		if curr in S:
			continue
		if curr == m:
			print(clicks)
			return
		S.add(curr)
		clicks += 1
		if curr > 1:
			Q.append((curr - 1, clicks))
		if curr < m:
			Q.append((2 * curr, clicks))
main()
if debug_mode:
	infile.close()


from sys import stdin
vals = [x for x in stdin.readline().split()]
m = int(vals[0])
n = int(vals[1])
solution = 0
if n > m:
	while n > m:
		if n % 2 == 0:
			solution += 1
			n /= 2
		else:
			solution += 1
			n += 1
if n < m:
	solution += m - n
print(int(solution))


line = input()
(num, finalNum) = line.split()
num = int(num)
finalNum = int(finalNum)
count = 0
while num != finalNum:
	if num > finalNum:
		count += num - finalNum
		num = finalNum
	elif finalNum % 2 == 0:
		finalNum /= 2
		count += 1
	else:
		finalNum += 1
		count += 1
print(int(count))


import sys

def read_input():
	inp = []
	for line in sys.stdin:
		d = line.split(' ')
		inp.append(int(d[0]))
		inp.append(int(d[1]))
	return inp

def __read_input():
	return [2, 10]

def solve(n, m):
	i = 0
	d = {}
	x = {}
	d.update({i: [n]})
	x.update({n: i})
	while x.get(m) == None or len(d[i]) == 0:
		d.update({i + 1: []})
		for k in d[i]:
			if k - 1 > 0 and x.get(k - 1) == None:
				d[i + 1].append(k - 1)
				x.update({k - 1: i})
			if k < m and x.get(2 * k) == None:
				d[i + 1].append(2 * k)
				x.update({2 * k: i})
		i += 1
	print(i)
inp = read_input()
solve(inp[0], inp[1])


import sys
(a, b) = map(int, input().split())
depth = 0
while True:
	red = b / 2
	blue = b + 1
	depth += 1
	if red == a or blue == a:
		print(depth)
		exit()
	elif not red == int(red):
		b = blue
	elif blue < a:
		b = blue
	else:
		b = red


(n, ex) = list(map(int, input().split()))
count = 0
if ex < n:
	print(n - ex)
else:
	(ex, n) = (n, ex)
	while True:
		if n < ex or n == ex:
			count += ex - n
			print(count)
			break
		elif n % 2 == 0:
			n //= 2
			count += 1
		elif n % 2 != 0:
			n += 1
			count += 1


(n, m) = [int(a) for a in input().split()]
amount = 0
if n > m:
	amount = n - m
else:
	while m > n:
		if m % 2 == 0:
			m //= 2
		else:
			m += 1
		amount += 1
	amount += n - m
print(amount)


import sys
import math
input = sys.stdin.readline
(a, b) = map(int, input().split())

def find(a, b, cnt):
	if a >= b:
		cnt += a - b
		return cnt
	elif b % 2 == 0:
		return find(a, b / 2, cnt + 1)
	else:
		return find(a, (b + 1) / 2, cnt + 2)
if a >= b:
	print(a - b)
else:
	ans = find(a, b, 0)
	print(int(ans))


from math import ceil, floor, log2
(n, m) = [int(x) for x in input().split()]
if m < n:
	print(n - m)
else:
	count = 0
	h = m
	while 1:
		h /= 2
		count += 1
		if h != int(h):
			count += 1
			h = ceil(h)
		if n >= h:
			count += n - ceil(h)
			break
	print(int(count))


line = input().split()
n = int(line[0])
m = int(line[1])
a = []
a += [n]
i = 1
node = i
level = 1
np = 0
visit = [0] * 10001
while len(a) > 0:
	if a[0] == m:
		print(visit[a[0]])
		break
	else:
		temp = a[0] * 2
		if temp < 10001 and visit[temp] == 0:
			a += [a[0] * 2]
			visit[temp] = visit[a[0]] + 1
		temp = a[0] - 1
		if temp > 0 and visit[temp] == 0:
			a += [a[0] - 1]
			visit[temp] = visit[a[0]] + 1
		a.pop(0)


from sys import stdin, stdout
import bisect
from bisect import bisect_left as bl
from bisect import bisect_right as br
import itertools
from collections import Counter
import collections
import math
import heapq
import re

def modinv(n, p):
	return pow(n, p - 2, p)

def cin():
	return map(int, sin().split())

def ain():
	return list(map(int, sin().split()))

def sin():
	return input()

def inin():
	return int(input())

def Divisors(n):
	l = []
	for i in range(1, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n // i == i:
				l.append(i)
			else:
				l.append(i)
				l.append(n // i)
	return l

def most_frequent(list):
	return max(set(list), key=list.count)

def GCD(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def ncr(n, r, p):
	t = fact[n] * (ifact[r] * ifact[n - r] % p) % p
	return t

def Convert(string):
	li = list(string.split(''))
	return li

def SieveOfEratosthenes(n):
	global prime
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	f = []
	for p in range(2, n):
		if prime[p]:
			f.append(p)
	return f
prime = []
q = []

def dfs(n, d, v, c):
	global q
	v[n] = 1
	x = d[n]
	q.append(n)
	j = c
	for i in x:
		if i not in v:
			f = dfs(i, d, v, c + 1)
			j = max(j, f)
	return j

def main():
	(n, m) = map(int, input().split())
	count = 0
	while n < m:
		if m & 1 == 0:
			m = m // 2
		else:
			m += 1
		count += 1
	print(count + n - m)
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
import os, sys
from io import IOBase, BytesIO
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.getvalue())
			(self.truncate(0), self.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			self.write = lambda s: self.buffer.write(s.encode('ascii'))
			self.read = lambda : self.buffer.read().decode('ascii')
			self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


(n, m) = [int(i) for i in input().split()]
c = 0
while True:
	if m == n:
		print(c)
		break
	if m % 2 == 1 or m < n:
		c += 1
		m += 1
	else:
		m = m // 2
		c += 1


import sys
from os import path
if path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
(n, m) = map(int, input().split())

def solve(n, m):
	if n >= m:
		return n - m
	if m <= 0:
		return 1000000
	if n == m:
		return 0
	if m % 2 == 0:
		return 1 + solve(n, m // 2)
	else:
		return 2 + solve(n, (m + 1) // 2)
if m < n:
	print(n - m)
	exit()
print(solve(n, m))


(n, m) = map(int, input().split())
cont = 0
while n < m:
	if m & 1:
		m += 1
	else:
		m = m // 2
	cont += 1
resultado = cont + (n - m)
print(resultado)


(n, mi) = map(int, input().split())
ras = 0
for i in range(100000):
	if n == mi:
		break
	if n > mi:
		ras = ras + 1
		mi = mi + 1
		continue
	elif mi % 2:
		mi = mi + 1
		ras = ras + 1
		continue
	elif mi % 2 == 0:
		mi = mi // 2
		ras += 1
		continue
print(ras)


from collections import deque
vis = [True for i in range(10004)]
(n, m) = input().split()
n = int(n)
m = int(m)
q = deque()
q.append([n, 0])
vis[n] = False
while True:
	cur = q.popleft()
	if cur[0] == m:
		break
	aux = cur[0] - 1
	if aux > 0 and vis[aux]:
		q.append([aux, cur[1] + 1])
		vis[aux] = False
	aux = cur[0] << 1
	if aux <= 10000 and vis[aux]:
		q.append([aux, cur[1] + 1])
		vis[aux] = False
print(cur[1])


(firstNum, secNum) = map(int, input().split())
step = 0
while secNum != firstNum:
	if firstNum > secNum:
		secNum += 1
		step += 1
	elif firstNum < secNum:
		if secNum % 2 == 0:
			secNum = secNum // 2
			step += 1
		else:
			secNum += 1
			step += 1
print(step)


from sys import stdin, stdout
from collections import Counter

def ai():
	return list(map(int, input().split()))

def ei():
	return map(int, input().split())

def ip():
	return int(stdin.readline())

def op(ans):
	return stdout.write(str(ans) + '\n')
(n, m) = ei()
queue = [(n, 0)]
seen = set()
seen.add(n)
while queue:
	(x, t) = queue.pop(0)
	if x == m:
		print(t)
		break
	if x > 1 and x - 1 not in seen:
		seen.add(x - 1)
		queue.append((x - 1, t + 1))
	if x < m and 2 * x not in seen:
		seen.add(2 * x)
		queue.append((2 * x, t + 1))


import sys

def minPress(startNumber, endNumber):
	numberList = []
	visited = {}
	numberList.append([startNumber, 0])
	visited[startNumber] = 0
	minCount = sys.maxsize
	while len(numberList) != 0:
		nextVal = numberList.pop()
		if nextVal[0] >= endNumber:
			tempCount = nextVal[1] + nextVal[0] - endNumber
			if tempCount < minCount:
				minCount = tempCount
		else:
			if nextVal[0] * 2 <= endNumber * 2 and (nextVal[0] * 2 not in visited or visited[nextVal[0] * 2] >= nextVal[1] + 1):
				visited[nextVal[0] * 2] = nextVal[1] + 1
				numberList.append([nextVal[0] * 2, nextVal[1] + 1])
			if nextVal[0] - 1 > 1 and (nextVal[0] - 1 not in visited or visited[nextVal[0] * 2] >= nextVal[1] + 1):
				visited[nextVal[0] - 1] = nextVal[1] + 1
				numberList.append([nextVal[0] - 1, nextVal[1] + 1])
	return minCount
(startNumber, endNumber) = [int(x) for x in sys.stdin.readline().split()]
print(minPress(startNumber, endNumber))


def find_path_count(x, y):
	if x == y:
		return 0
	if x > y:
		return x - y
	paths = {x: 0}
	count = x * y
	max_t = 2 * y
	cur_i = -1
	results = []
	while True:
		new_items = {}
		cur_i += 1
		for (t, v) in paths.items():
			t1 = t - 1
			t2 = t * 2
			if t1 == y:
				res = v + 1
				return res
			if t2 == y:
				res = v + 1
				return res
			if t1 not in paths and t1 > 1:
				new_items[t1] = v + 1
			if t2 not in paths:
				if t2 < y or t2 < max_t:
					if t2 > y:
						count = min(count, t2 - y + v)
					new_items[t2] = v + 1
		paths = new_items
		if cur_i >= count:
			count
(x, y) = map(int, input().split(' '))
print(find_path_count(x, y))


from collections import deque

def bfs(start, finish):
	queue = deque()
	visited = set()
	item = (0, start)
	queue.appendleft(item)
	while queue:
		(level, val) = queue.pop()
		if val in visited:
			continue
		visited.add(val)
		if val == finish:
			return level
		if val - 1 > -1 and val - 1 not in visited:
			queue.appendleft((level + 1, val - 1))
		if val * 2 < finish + 2 and val * 2 not in visited:
			queue.appendleft((level + 1, val * 2))
count = 0
(start, finish) = tuple(map(int, input().split()))
print(bfs(start, finish))


from collections import defaultdict, deque

def bfs(start, end, visitados):
	fila = deque()
	fila.append((0, start))
	while fila:
		(apertos, vertice) = fila.popleft()
		if vertice == end:
			return apertos
		if vertice in visitados:
			continue
		visitados.add(vertice)
		if vertice < end:
			fila.append((apertos + 1, vertice * 2))
		if vertice - 1 >= 1:
			fila.append((apertos + 1, vertice - 1))
(graph, visitados) = (defaultdict(set), set())
(start, end) = map(int, input().split())
print(bfs(start, end, visitados))


import sys
(b, e) = list(map(int, input().split()))
if b >= e:
	print(b - e)
	sys.exit()
count = 0
while b is not e:
	if e > b:
		if e % 2 is 0:
			e = e // 2
		else:
			e = e + 1
	else:
		count = count + b - e
		break
	count = count + 1
print(count)


import sys
(n, m) = map(int, input().split())
count = 0
if m <= n:
	print(n - m)
	sys.exit(0)
while n != m:
	if n < m:
		if m % 2 == 0:
			m = m / 2
		else:
			m = m + 1
	else:
		break
	count = count + 1
print(int(n - m + count))


from queue import Queue
(n, m) = map(int, input().split())
MAX = 20000
d = {}
q = Queue()
q.put(n)
d[n] = 0
while not q.empty():
	x = q.get()
	if x == m:
		break
	if x * 2 <= MAX and x * 2 not in d:
		d[x * 2] = d[x] + 1
		q.put(x * 2)
	if x - 1 >= 1 and x - 1 not in d:
		d[x - 1] = d[x] + 1
		q.put(x - 1)
print(d[m])


(n, aim) = map(int, input().split())
step = 0
while 1:
	if aim < n:
		step += n - aim
		print(step)
		break
	elif aim > n:
		if aim % 2 == 0:
			aim = aim // 2
			step += 1
		else:
			aim += 1
			step += 1
	else:
		print(step)
		break


(n, m) = map(int, input().strip().split(' '))
Step = 0
while n != m:
	if m < n or m % 2 != 0:
		m += 1
	elif m > n:
		m = int(m / 2)
	Step += 1
print(Step)


import sys
import heapq
from math import ceil, floor, gcd, fabs, factorial, fmod, sqrt
from collections import defaultdict as dd, deque, Counter as c
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
mod = pow(10, 9) + 7
mod2 = 998244353

def data():
	return sys.stdin.readline().strip()

def out(var):
	sys.stdout.write(str(var))

def l():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [[val for i in range(n)] for j in range(m)]
(n, m) = sp()
if n >= m:
	out(n - m)
	exit()
graph = dd(set)
q = deque()
q.append(n)
dist = dd(lambda : sys.maxsize)
occured = set()
while len(q):
	temp = q.popleft()
	if temp - 1 >= 0 and temp - 1 not in occured:
		graph[temp].add(temp - 1)
		q.append(temp - 1)
		occured.add(temp - 1)
	if 2 * temp <= 2 * m and 2 * temp not in occured:
		graph[temp].add(2 * temp)
		q.append(2 * temp)
		occured.add(2 * temp)

def shortest_path(source, target):
	d = deque()
	d.append(source)
	dist[source] = 0
	while len(d):
		temp = d.popleft()
		for i in graph[temp]:
			dist[i] = dist[temp] + 1
			d.append(i)
			if i == target:
				return dist[i]
out(shortest_path(n, m))


def answer2(N, M, count):
	if M <= N:
		return count + N - M
	if M % 2 != 0:
		count += 1
		M += 1
	return answer2(N, M // 2, count + 1)
(N, M) = map(int, input().split())
print(answer2(N, M, 0))


(s, t) = map(int, input().split())
c = 0
while True:
	if t < s:
		print(s - t + c)
		quit()
	else:
		if t == s:
			print(c)
			quit()
		if t % 2 == 0:
			c += 1
			t //= 2
		else:
			c += 2
			t //= 2
			t += 1


import math
from decimal import *

def pfacts(n):
	ans = []
	if n % 2 == 0:
		ans.append(2)
		while n % 2 == 0:
			n //= 2
	p = 3
	while n != 1:
		if n % p == 0:
			ans.append(p)
			while n % p == 0:
				n //= p
		p += 1
	return ans
(n, m) = map(int, input().split())
if m == n:
	print(0)
elif m < n:
	print(n - m)
else:
	ans = 0
	while n < m:
		if m % 2 == 0:
			m //= 2
		else:
			m += 1
		ans += 1
	if m != n:
		ans += n - m
	print(ans)


def tt(n, m):
	if m <= n:
		return n - m
	if m % 2 == 0:
		return 1 + tt(n, m / 2)
	return 1 + tt(n, m + 1)
(n, m) = [int(v) for v in input().split()]
print(int(tt(n, m)))


(start, goal) = [int(x) for x in input().split()]
if start >= goal:
	print(start - goal)
else:
	temp = goal
	steps = 0
	while temp != start:
		if temp > start:
			if temp % 2 == 0:
				temp = temp // 2
			else:
				temp += 1
		else:
			temp += 1
		steps += 1
	print(steps)


import os
import sys
from io import BytesIO, IOBase

def solution(n, m):
	if n >= m:
		write(n - m)
		return
	res = 0
	if m & 1:
		m += 1
		res += 1
	while m > n:
		m //= 2
		res += 1
		if m == n:
			write(res)
			return
		if m < n:
			break
		if m & 1:
			m += 1
			res += 1
	res += n - m
	write(res)

def main():
	(n, m) = r_array()
	solution(n, m)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')

def write(*args, sep=' ', end='\n'):
	for x in args[:-1]:
		sys.stdout.write(str(x) + sep)
	sys.stdout.write(str(args[-1]) + end)

def r_array():
	return [int(x) for x in input().split()]

def r_int():
	return int(input())
main()


(n, m) = map(int, input().split())
if n >= m:
	print(n - m)
else:
	k = 0
	while m > n:
		k += 1 + m % 2
		m = round((m + m % 2) / 2)
	k += n - m
	print(k)


(n, m) = (int(i) for i in input().split())
operations = 0
while n != m:
	if m % 2 == 0 and m > n:
		m //= 2
	else:
		m += 1
	operations += 1
print(operations)


(n, m) = map(int, input().split())
ans = [-1 for i in range(10 ** 5)]
q = [0 for i in range(10 ** 5)]
le = rg = 0
q[le] = n
ans[n] = 0

def add(x, t):
	global le, rg, q, ans
	if ans[x] != -1:
		return
	ans[x] = ans[t] + 1
	rg += 1
	q[rg] = x
while le <= rg:
	top = q[le]
	le += 1
	if top < m:
		add(top * 2, top)
	if top > 0:
		add(top - 1, top)
print(ans[m])


(n, m) = map(int, input().split())
stepnums = [-1] * 20000
stepnums[n] = 0
queue = []
queue.append(n)
while len(queue) > 0:
	current = queue.pop(0)
	if current == m:
		print(stepnums[current])
		break
	if current * 2 < 2 * 10 ** 4 and stepnums[current * 2] == -1:
		queue.append(current * 2)
		stepnums[current * 2] = stepnums[current] + 1
	if current - 1 >= 0 and stepnums[current - 1] == -1:
		queue.append(current - 1)
		stepnums[current - 1] = stepnums[current] + 1


(n, m) = map(int, input().split())

def problem2(n, m):
	if n == m:
		return '0'
	cont = 0
	while n != m:
		if n > m:
			return cont + (n - m)
		if m % 2 == 0:
			m = m // 2
		else:
			m += 1
		cont += 1
		if cont > 60:
			break
	return cont
print(problem2(n, m))


from collections import deque
(n, m) = map(int, input().strip().split())
q = deque([(n, 0)])
seen = set()
while q:
	(n, cost) = q.popleft()
	if n in seen:
		continue
	seen.add(n)
	if n == m:
		print(cost)
		break
	if n - 1 >= 1:
		q.append([n - 1, cost + 1])
	if n < m:
		q.append([n * 2, cost + 1])


import sys
from collections import defaultdict
sys.setrecursionlimit(10 ** 6)
mod = 1000000007

def get_array():
	return list(map(int, sys.stdin.readline().split()))

def get_ints():
	return map(int, sys.stdin.readline().split())

def input():
	return sys.stdin.readline()

def print_array(a):
	print(' '.join(map(str, a)))

def main():
	(n, m) = get_ints()
	if n >= m:
		print(n - m)
	else:
		t = 0
		while m > n:
			if m % 2 == 0:
				m = m // 2
				t += 1
			else:
				m = m + 1
				t += 1
		print(t + (n - m))
main()


from collections import deque
queue = deque()
cache = set()
(n, m) = map(int, input().split())
queue.append((n, 0))
while queue:
	current = queue.popleft()
	if current[0] < 0:
		continue
	if current[0] == m:
		print(current[1])
		break
	red = current[0] * 2
	if red not in cache and current[0] < m:
		queue.append((red, current[1] + 1))
		cache.add(red)
	blue = current[0] - 1
	if blue not in cache:
		queue.append((blue, current[1] + 1))
		cache.add(blue)


import math
(n, m) = map(int, input().split())
res = 0
next = []
x = m
while x > n:
	next.append(math.ceil(x))
	x /= 2
next.append(math.ceil(x))
next = next[::-1]
num = next[0]
i = 1
res += n - num
while num != m:
	res += 1
	num *= 2
	res += num - next[i]
	num = next[i]
	i += 1
print(res)


def sp(adj, src, des):
	que = []
	que.append(src)
	dist = {src: 0}
	flag = 0
	while que:
		f = que[0]
		que.pop(0)
		for i in adj[f]:
			if i not in dist:
				que.append(i)
				dist[i] = dist[f] + 1
			if i == des:
				flag = 1
				break
		if flag == 1:
			break
	return dist[des]
(n, m) = map(int, input().split())
adj = {}
vertices = [i for i in range(1, 2 * max(m, n) + 1)]
for i in vertices:
	if i == 1:
		adj[i] = [2 * i]
	elif 2 * i > 2 * m:
		adj[i] = [i - 1]
	else:
		adj[i] = [i - 1, 2 * i]
print(sp(adj, n, m))


(n, m) = map(int, input().split())
h = 1
q = [n]
k = 2 * 10 ** 4 + 1
popa = [0 for i in range(2 * 10 ** 4 + 1)]
if n > m:
	print(n - m)
else:
	visited = []
	while q:
		n = []
		for i in q:
			if i * 2 not in visited and i < 2 * m:
				if 2 * i == m:
					print(h)
					exit()
				n.append(i * 2)
				visited.append(2 * i)
			if i - 1 not in visited and i > 1:
				visited.append(i - 1)
				if i - 1 == m:
					print(h)
					exit()
				n.append(i - 1)
				visited.append(2 * i)
		q = n
		h += 1


(a, b) = list(map(int, input().split()))
n = 0
while b != a:
	if b < a:
		b += 1
		n += 1
		continue
	if b % 2 == 0:
		b = b / 2
		n += 1
		continue
	if b % 2 == 1:
		b = b + 1
		n += 1
		continue
print(n)


lists = []
list_count = [1]
visited = set()
count = 0

def find_short(end):
	global count, lists, list_count, visited
	while len(lists) != 0:
		current = lists[0]
		current_count = list_count[0]
		lists = lists[1:]
		list_count = list_count[1:]
		if current == end:
			if current_count == 0:
				count = count - 1
			return count
		if current in visited:
			if current_count == 1:
				list_count[0] = 1
			continue
		if current < 0:
			continue
		visited.add(current)
		if current < end:
			if current_count != 0:
				list_count.append(1)
				list_count.append(0)
			else:
				list_count.append(0)
				list_count.append(0)
			lists.append(current * 2)
			lists.append(current - 1)
		else:
			if current_count != 0:
				list_count.append(1)
			else:
				list_count.append(0)
			lists.append(current - 1)
		count += current_count
	return -1

def main():
	input_val = input()
	dicti = input_val.split(' ')
	start = int(dicti[0])
	end = int(dicti[1])
	lists.append(start)
	result = find_short(end)
	print(result)
	return result
main()


class Queue:

	def __init__(self):
		self.list = []

	def push(self, value):
		self.list.append(value)

	def pop(self):
		return self.list.pop(0)

	def top(self):
		return self.list[0]

	def empty(self):
		return len(self.list) == 0
(n, m) = map(int, input().split())
MAX_VALUE = 2 * max(n, m)
q = Queue()
q.push(n)
count = [0 for i in range(MAX_VALUE + 1)]
while q.top() != m:
	u = q.pop()
	if u - 1 >= 0 and count[u - 1] == 0:
		count[u - 1] = count[u] + 1
		q.push(u - 1)
	if u * 2 <= MAX_VALUE and count[u * 2] == 0:
		count[u * 2] = count[u] + 1
		q.push(u * 2)
print(count[m])


(n, m) = map(int, input().split())
i = 0
while n != m:
	if not m % 2 and m > n:
		m //= 2
	else:
		m += 1
	i += 1
print(i)


(n, m) = map(int, input().split())
q = 0
while n != m:
	m = [m // 2, m + 1][m & 1 or m < n]
	q += 1
print(q)


(n, m) = [int(x) for x in input().split()]
s = 0
while n < m:
	s += 1 + m % 2
	m = (m + m % 2) // 2
print(s + n - m)


from collections import deque

def mini(n, m):
	dic = {}
	if n == m:
		return 0
	if n > m:
		for i in range(1, n + 1):
			dic[i] = []
			if i * 2 <= n:
				dic[i].append(i * 2)
			if 0 < i - 1:
				dic[i].append(i - 1)
	else:
		for i in range(1, 2 * m + 1):
			dic[i] = []
			if i * 2 <= 2 * m:
				dic[i].append(i * 2)
			if 0 < i - 1:
				dic[i].append(i - 1)
	dist = bfs(dic, n)
	return dist[m]

def bfs(graph, n):
	lst = deque([n])
	temp = n
	visit = {}
	dist = {}
	for i in graph:
		dist[i] = 0
	for i in graph:
		visit[i] = False
	visit[n] = True
	while lst != deque():
		temp = lst.popleft()
		for i in graph[temp]:
			if visit[i]:
				continue
			dist[i] = 1 + dist[temp]
			visit[i] = True
			lst.append(i)
	return dist
mini(10, 1)
arr = list(map(int, input().split()))
(n, m) = arr
print(mini(n, m))


def count_minor_ops(a, b):
	ops = 0
	while True:
		if a == b:
			break
		elif b < a:
			ops += a - b
			break
		elif b % 2 == 0:
			b = b // 2
		else:
			b += 1
		ops += 1
	return ops
(a, b) = list(map(int, input().split()))
print(count_minor_ops(a, b))


import sys
input = sys.stdin.readline

def ceil(x):
	if x != int(x):
		x = int(x) + 1
	return x

def factorial(x, m):
	val = 1
	while x > 0:
		val = val * x % m
		x -= 1
	return val

def fact(x):
	val = 1
	while x > 0:
		val *= x
		x -= 1
	return val

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def nCr(n, k):
	if k > n:
		return 0
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return int(res)

def upper_bound(a, x, lo=0, hi=None):
	if hi == None:
		hi = len(a)
	while lo < hi:
		mid = (lo + hi) // 2
		if a[mid] < x:
			lo = mid + 1
		else:
			hi = mid
	return lo

def primefs(n):
	primes = {}
	while n % 2 == 0 and n > 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0 and n > 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	p = x
	while p != link[p]:
		p = link[p]
	while x != p:
		nex = link[x]
		link[x] = p
		x = nex
	return p

def union(x, y, link, size):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	prime = [True for i in range(n + 1)]
	(prime[0], prime[1]) = (False, False)
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime
MAXN = int(100000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i
spf = [0 for i in range(MAXN)]

def factoriazation(x):
	res = []
	for i in range(2, int(x ** 0.5) + 1):
		while x % i == 0:
			res.append(i)
			x //= i
	if x != 1:
		res.append(x)
	return res

def int_array():
	return list(map(int, input().strip().split()))

def float_array():
	return list(map(float, input().strip().split()))

def str_array():
	return input().strip().split()
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
from itertools import permutations
import math
from bisect import bisect_left

def solve():
	(n, m) = map(int, input().split())
	if n >= m:
		print(abs(n - m))
		return
	c = 0
	while m != n:
		if m % 2 == 1 or m < n:
			m += 1
			c += 1
		else:
			m //= 2
			c += 1
	print(c)
for _ in range(1):
	solve()


import queue as queue
from collections import defaultdict

class node:

	def __init__(self, h=None, d=None, l=None, r=None):
		self.data = d
		self.lc = l
		self.rc = r
		self.height = h

	def setrc(self, r):
		self.rc = r

	def setlc(self, l):
		self.lc = l

	def geth(self):
		return self.height

	def getdata(self):
		return self.data

class tree:

	def __init__(self, d):
		n = node(0, d)
		self.root = n

	def bfs(self, a):
		n = self.root
		if n.getdata() == a:
			return 0
		q = queue.Queue()
		dd = defaultdict(int)
		q.put(n)
		while True:
			b = q.get()
			h = b.geth()
			d = b.getdata()
			if dd[d] == 0:
				dd[d] = 1
				d1 = d - 1
				d2 = d * 2
				if d1 == a or d2 == a:
					return h + 1
				if d1 > 0:
					n1 = node(h + 1, d1)
					b.setlc(n1)
					q.put(n1)
				if d < a:
					n2 = node(h + 1, d2)
					b.setrc(n2)
					q.put(n2)
(n, m) = map(int, input().split(' '))
t = tree(n)
print(t.bfs(m))


(n, m) = list(map(int, input().split()))
cnt = 0
l = n
while l < m:
	cnt += 1
	l *= 2
dif = l - m
val = 2 ** cnt
while dif > 0:
	cnt += dif // val
	dif %= val
	val //= 2
print(cnt)


nums = str(input()).split()
fr = int(nums[0])
t = int(nums[1])

def diff(a, b):
	if b <= a:
		return a - b
	elif b % 2 == 0:
		return diff(a, b / 2) + 1
	else:
		return diff(a, (b + 1) / 2) + 2
print(int(diff(fr, t)))


import heapq
from collections import deque
(start, target) = [int(i) for i in input().strip().split()]
stack = deque([(start, 0)])
seen = set()
seen.add(start)
while len(stack):
	(node, count) = stack.pop()
	if node == target:
		print(count)
		break
	if node * 2 not in seen:
		if node < target:
			seen.add(node * 2)
			stack.appendleft((node * 2, count + 1))
	if node - 1 not in seen and node - 1 >= 0:
		seen.add(node - 1)
		stack.appendleft((node - 1, count + 1))


(N, M) = map(int, input().split())
queue = [N]
d = [-1 for i in range(100010)]
d[N] = 0
while queue:
	p = queue.pop(0)
	if p < 0:
		continue
	if d[p - 1] == -1:
		if p - 1 == M:
			print(d[p] + 1)
			exit()
		d[p - 1] = d[p] + 1
		queue.append(p - 1)
	if p * 2 > max(N, M) * 2:
		continue
	if d[p * 2] == -1:
		if p * 2 == M:
			print(d[p] + 1)
			exit()
		d[p * 2] = d[p] + 1
		queue.append(p * 2)


(n1, m1) = map(int, input().split())
if m1 <= n1:
	print(n1 - m1)
else:
	t = 0
	while m1 > n1:
		if m1 % 2 == 0:
			m1 = m1 // 2
			t = t + 1
		else:
			m1 = m1 + 1
			t = t + 1
	print(t + n1 - m1)


from collections import deque
(n, m) = list(map(int, input().split()))
q = deque()
q.append([n, 0])
size = 1
d = dict()
d[n] = 0
while size != 0:
	(s1, s2) = q.popleft()
	size = size - 1
	if s1 == m:
		print(s2)
		break
	else:
		if s1 <= m:
			if d.get(s1 * 2) == None:
				q.append([s1 * 2, s2 + 1])
				d[s1 * 2] = 1
				size = size + 1
		if s1 >= 0:
			if d.get(s1 - 1) == None:
				q.append([s1 - 1, s2 + 1])
				d[s1 - 1] = 1
				size = size + 1


(n, m) = map(int, input().split())
done = {n}
frontier = {n}
i = 0
while True:
	i += 1
	new_f = set()
	for e in frontier:
		for v in (e * 2, e - 1):
			if v < 0 or v in done or v > 20000:
				continue
			if v == m:
				print(i)
				exit()
			done.add(v)
			new_f.add(v)
	frontier = set()
	for e in new_f:
		frontier.add(e)


def findShortest(n, m):
	count = 0
	if n > m:
		count += n - m
		n = m
	while n < m:
		count += 1
		if m % 2 == 0:
			m //= 2
		else:
			m += 1
	return count + n - m
(n, m) = (int(x) for x in input().split(' '))
print(findShortest(n, m))


(x, y) = map(int, input().split())
c = 0
for i in range(10000):
	if y > x:
		if y % 2 != 0:
			y = y + 1
			c = c + 1
		else:
			y = y // 2
			c = c + 1
	elif y < x:
		c = c + (x - y)
		print(c)
		break
	else:
		print(c)
		break


import sys
from itertools import *
from cmath import *
input = sys.stdin.readline
from math import *

def inp():
	return int(input().strip())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())

def iss(s):
	return s == s[::-1]
(a, b) = invr()
cs = 0
if b < a:
	print(a - b)
else:
	while b > a:
		if b % 2 == 0:
			b //= 2
		else:
			b += 1
		cs += 1
	print(abs(cs + a - b))


from queue import Queue
import random

def soln(n, m):
	q = Queue()
	seen = set([])
	q.put((n, 0))
	while not q.empty():
		(curr, numClicks) = q.get()
		if curr in seen:
			continue
		if curr == m:
			return numClicks
		if curr >= 2 * max(m, n) or curr <= min(m, n) // 2:
			continue
		seen.add(curr)
		nxts = [curr - 1, 2 * curr]
		random.shuffle(nxts)
		for nxt in nxts:
			q.put((nxt, numClicks + 1))
	return -1

def main():
	(n, m) = [int(x) for x in input().split()]
	result = soln(n, m)
	print(result)
main()


(n, m) = map(int, input().split())
answer = 0
while True:
	red = m / 2
	blue = m + 1
	answer += 1
	if red == n or blue == n:
		break
	elif not red == int(red):
		m = blue
	else:
		tryred = abs(1 - red / n)
		tryblue = abs(1 - blue / n)
		if tryred < tryblue:
			m = red
		elif blue < n:
			m = blue
		else:
			m = red
print(answer)


(n, m) = map(int, input().split())

class SiteGame:

	def __init__(self, n, m):
		self.n = n
		self.m = m
		opirationNumber = 0
		if m <= n:
			opirationNumber += n - m
			print(opirationNumber)
			return
		while True:
			if m % 2 == 1:
				m += 1
				opirationNumber += 1
			m = m // 2
			opirationNumber += 1
			if m <= n:
				break
		opirationNumber += n - m
		print(opirationNumber)
SiteGame(n, m)


def Main(n, m):
	cnt = 0
	lft = n
	rgt = m
	while True:
		if lft == rgt:
			break
		if lft < rgt:
			if rgt % 2 == 1:
				rgt += 1
				rgt //= 2
				cnt += 2
			else:
				rgt //= 2
				cnt += 1
		elif lft > rgt:
			cnt += lft - rgt
			rgt += lft - rgt
	print(cnt)
(n, m) = map(int, input().split())
Main(n, m)


import math

def solve():
	(n, m) = list(map(int, input().split(' ')))
	if m <= n:
		print(n - m)
		return
	multiplier = int(math.ceil(math.log2(m / n)))
	count = 2 ** multiplier * n - m
	total = multiplier
	for i in range(multiplier):
		if count <= 1:
			break
		elif count % 2 == 1:
			total += 1
		count = count // 2
	print(total + count)
solve()


from queue import Queue
(n, m) = map(int, input().split())
visited = {n}
if m < n:
	print(n - m)
else:
	q = Queue()
	q.put((n, 0))
	while q.qsize():
		(k, t) = q.get()
		if k == m:
			print(t)
			break
		if k - 1 not in visited and k > 0:
			q.put((k - 1, t + 1))
			visited.add(k - 1)
		if k * 2 not in visited and k < m:
			q.put((k * 2, t + 1))
			visited.add(k * 2)


(n, m) = list(map(int, input().split()))
d = [-1] * 30000
d[n] = 0
head = 0
tail = 1
q = []
q.append(n)
while head < tail:
	v = q[head]
	head += 1
	if v > 1 and d[v - 1] == -1:
		d[v - 1] = d[v] + 1
		q.append(v - 1)
		tail += 1
	if v <= m and d[2 * v] == -1:
		d[2 * v] = d[v] + 1
		q.append(2 * v)
		tail += 1
print(d[m])


(n, m) = map(int, input().split())
a = 0

def soma(n, m, a):
	while n < m:
		if m & 1:
			m += 1
		else:
			m = m // 2
		a += 1
	return a + (n - m)
a = soma(n, m, a)
if n < m:
	if a == 0:
		print(n - m)
	else:
		print(a)
else:
	print(n - m)


(n, m) = list(map(int, input().split()))
cnt = 0
while n < m:
	if m % 2 == 1:
		m += 1
		cnt += 1
	else:
		m //= 2
		cnt += 1
cnt += abs(m - n)
print(cnt)


(m, n) = map(int, input().split())
value = n
count = 0
while True:
	if value == m:
		break
	if value < m:
		value += 1
		count += 1
	elif value % 2 == 1:
		value += 1
		count += 1
	else:
		value = value // 2
		count += 1
print(count)


inS = input()
nums = [int(i) for i in inS.split(' ')]
n = nums[0]
m = nums[1]
dp_arr = [99999] * (10 ** 4 + 1)
dp_arr[n] = 0
for i in range(n, 0, -1):
	dp_arr[i] = n - i
for i in range(1, len(dp_arr)):
	if i + 1 < len(dp_arr):
		dp_arr[i] = min(dp_arr[i], dp_arr[i + 1] + 1)
	if i * 2 < len(dp_arr):
		dp_arr[i * 2] = min(dp_arr[i * 2], dp_arr[i] + 1)
print(dp_arr[m])


count = 0
(m, n) = [int(x) for x in input().split()]
queue = [(m, 0)]
visited = set([m])
minstep = float('inf')
while queue:
	(num, step) = queue.pop(0)
	if num == n:
		if step < minstep:
			minstep = step
	if num > n:
		adder = num - n
		queue.append((n, step + adder))
	else:
		for adder in [lambda x: x - 1, lambda x: x * 2]:
			ne = adder(num)
			if ne == n or (ne not in visited and ne > 0):
				queue.append((ne, step + 1))
				visited.add(ne)
print(minstep)


import math
(n, m) = list(map(int, input().split()))
count = 0
while m > n:
	if m % 2 == 0:
		m = m // 2
		count += 1
	else:
		m = (m + 1) // 2
		count += 2
count += n - m
print(count)


from collections import deque
limit = [0, 10 ** 4 * 2 + 1]
(n, m) = map(int, input().split())
was = set()
q = deque([[n, 0]])
while q:
	(v, k) = q.popleft()
	if v == m:
		print(k)
		break
	if v - 1 > limit[0] and v - 1 not in was:
		was.add(v - 1)
		q.append((v - 1, k + 1))
	if v * 2 < limit[1] and v * 2 not in was:
		was.add(v * 2)
		q.append((v * 2, k + 1))


import sys, os, io

def rs():
	return sys.stdin.readline().rstrip()

def ri():
	return int(sys.stdin.readline())

def ria():
	return list(map(int, sys.stdin.readline().split()))

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
import math, datetime, functools, itertools, operator, bisect, fractions, statistics
from collections import deque, defaultdict, OrderedDict, Counter
from fractions import Fraction
from decimal import Decimal
from sys import stdout
from heapq import heappush, heappop, heapify, _heapify_max, _heappop_max, nsmallest, nlargest
sys.setrecursionlimit(111111)
INF = 99999999999999999999999999999999

def main():
	mod = 1000000007
	starttime = datetime.datetime.now()
	if os.path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	tc = 1
	for _ in range(tc):
		(n, M) = ria()
		m = max(n, M)
		visited = [0] * (2 * m + 1)
		dist = [0] * (m * 2 + 1)
		q = deque([n])
		visited[n] = 1
		while len(q) and dist[M] == 0:
			parent = q.popleft()
			if parent * 2 <= 2 * m and visited[parent * 2] == 0:
				visited[parent * 2] = 1
				q.append(parent * 2)
				dist[parent * 2] = dist[parent] + 1
			if parent - 1 >= 0 and visited[parent - 1] == 0:
				visited[parent - 1] = 1
				q.append(parent - 1)
				dist[parent - 1] = dist[parent] + 1
		wi(dist[M])
	endtime = datetime.datetime.now()
	time = (endtime - starttime).total_seconds() * 1000
	if os.path.exists('input.txt'):
		print('Time:', time, 'ms')

class FastReader(io.IOBase):
	newlines = 0

	def __init__(self, fd, chunk_size=1024 * 8):
		self._fd = fd
		self._chunk_size = chunk_size
		self.buffer = io.BytesIO()

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self, size=-1):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size if size == -1 else size))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

class FastWriter(io.IOBase):

	def __init__(self, fd):
		self._fd = fd
		self.buffer = io.BytesIO()
		self.write = self.buffer.write

	def flush(self):
		os.write(self._fd, self.buffer.getvalue())
		(self.buffer.truncate(0), self.buffer.seek(0))

class FastStdin(io.IOBase):

	def __init__(self, fd=0):
		self.buffer = FastReader(fd)
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

class FastStdout(io.IOBase):

	def __init__(self, fd=1):
		self.buffer = FastWriter(fd)
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.flush = self.buffer.flush
sys.stdin = FastStdin()
sys.stdout = FastStdout()
main()


import sys
import queue as q
first_line = input()
n = int(first_line.split(' ')[0])
m = int(first_line.split(' ')[1])

class Node:

	def __init__(self, value, depth):
		self.value = value
		self.depth = depth

	def red(self):
		self.value += 1
		self.depth += 1

	def blue(self):
		self.value = self.value >> 1
		self.depth += 1

	def odd(self):
		return self.value & 1

	def getDepth(self):
		return self.depth

	def getValue(self):
		return self.value
node = Node(m, 0)
while True:
	if node.getValue() > n:
		if node.odd():
			node.red()
		else:
			node.blue()
	elif n > node.getValue():
		node.red()
	else:
		print(node.getDepth())
		sys.exit()


def cord(x, y):
	if x >= y:
		return x - y
	if y % 2 != 0:
		return 1 + cord(x, y + 1)
	else:
		return 1 + cord(x, y // 2)
(a, b) = (int(i) for i in input().split())
print(cord(a, b))


from sys import stdin
(n, m) = str(stdin.readline()).replace('\n', '').split(' ')
n = int(n)
m = int(m)
i = 0
if n >= m:
	print(n - m)
else:
	while m != n:
		if m % 2 == 0 and n < m:
			m = m / 2
			i = i + 1
		elif m % 2 == 1 and n < m:
			m = m + 1
			m = m / 2
			i = i + 2
		elif n > m:
			m = m + 1
			i = i + 1
	print(i)


(n, m) = map(int, input().split())
checker = 0
while n < m:
	if m % 2 == 1:
		m += 1
		checker += 1
	m /= 2
	checker += 1
while n > m:
	m += 1
	checker += 1
print(checker)


def bfs(n, m):
	queue = [[n, 0]]
	d = {}
	x = 2 * m
	while queue:
		q = queue.pop(0)
		(v, k) = (q[0], q[1])
		if v == m:
			return k
		e = v - 1
		if e > 0:
			if d.get(e) == None:
				d[e] = 0
				queue.append([e, k + 1])
		e = v * 2
		if e <= x:
			if d.get(e) == None:
				d[e] = 0
				queue.append([e, k + 1])
(n, m) = map(int, input().split())
if n >= m:
	print(n - m)
else:
	print(bfs(n, m))


import sys
sys.setrecursionlimit(100000)

def _(lista, m, counter=1, visitado={}):
	temporal = []
	for i in lista:
		l = i - 1
		r = i * 2
		if r < 2 * m:
			if r not in visitado:
				temporal += [r]
				visitado[r] = 0
		if l > 0:
			if l not in visitado:
				temporal += [l]
				visitado[l] = 0
	lista = temporal
	if m in visitado:
		return counter
	else:
		return _(lista, m, counter + 1)
(n, m) = map(int, input().split())
if m < n:
	print(n - m)
else:
	print(_([n], m))


import math
s = list(map(int, input().split()))
a = s[0]
b = s[1]
m = 0
n = 0
delta = 0
step = 0
if a >= b:
	print(a - b)
else:
	m = math.ceil(math.log2(b / a))
	delta = a * 2 ** m - b
	n = math.ceil(math.log2(b))
	j = 0
	while j <= m:
		step += delta // 2 ** (m - j)
		delta = delta % 2 ** (m - j)
		j += 1
	step += m
	print(step)


import math
(n, k) = tuple(map(int, input().split()))
x = k
i = 0
while x > n:
	if x % 2 == 1:
		x += 1
		i += 1
	x //= 2
	i += 1
i += n - x
print(i)


import sys

def search(n, m, res):
	if n == m:
		return res
	if n > m:
		return res + (n - m)
	if m % 2 == 0:
		return search(n, m // 2, res + 1)
	return search(n, m + 1, res + 1)

def main():
	f = sys.stdin
	(n, m) = map(int, f.readline().rstrip().split())
	print(search(n, m, 0))
main()


(n, m) = map(int, input().split())
if n >= m:
	(print(n - m), exit())
v = [-1] * (2 * m)
v[m] = 0
q = [m]
while q:
	cur = q.pop(0)
	d = v[cur]
	if cur < 2 * m - 1 and v[cur + 1] == -1:
		v[cur + 1] = d + 1
		q.append(cur + 1)
	if cur % 2 == 0 and v[cur // 2] == -1:
		v[cur // 2] = d + 1
		q.append(cur // 2)
print(v[n])


q = input().split()
x = int(q[0])
p = int(q[1])
count = 0
while x < p:
	if p % 2 == 0:
		p = int(p / 2)
		count += 1
	else:
		p = p + 1
		p = int(p / 2)
		count += 2
if p == x:
	count = count + 0
else:
	count = count + x - p
print(count)


import sys
input_list = input().split()
beg = int(input_list[0])
end = int(input_list[1])
steps = 0
while end > beg:
	if end % 2 == 1:
		end = end + 1
	else:
		end = end / 2
	steps = steps + 1
diff = abs(beg - end)
steps = steps + diff
print(int(steps))


import os
import sys
from math import *
from collections import *
from bisect import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def value():
	return tuple(map(int, input().split()))

def array():
	return [int(i) for i in input().split()]

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]

def bfs(adj, s, d):
	vis = defaultdict(bool)
	vis[s] = True
	qu = [s]
	papa = defaultdict(int)
	while len(qu) != 0:
		e = qu.pop(0)
		if e == d:
			return papa
		f = False
		for i in adj[e]:
			if vis[i] != True:
				f = True
				qu.append(i)
				vis[i] = True
				papa[i] = e
(n, m) = value()
adj = defaultdict(list)
adj[0].append(2)
for i in range(1, 2 * max(n, m) + 1):
	adj[i].append(2 * i)
	adj[i].append(i - 1)
papa = bfs(adj, n, m)
steps = 1
while papa[m] != n:
	steps += 1
	m = papa[m]
print(steps)


def botoes(n, m):
	op = 0
	while True:
		if m == n:
			return op
		if m < n:
			return op + int(n - m)
		if m % 2 == 0:
			m /= 2
			op += 1
		else:
			m += 1
			op += 1
NM = [int(i) for i in input().split()]
n = NM[0]
m = NM[1]
print(botoes(n, m))


inputArray = input().split(' ')
n = int(inputArray[0])
m = int(inputArray[1])
count = 0
if n == m:
	print(int(0))
elif m < n:
	print(int(n - m))
else:
	while m > n:
		if m % 2 == 0:
			m = m / 2
		else:
			m = m + 1
		count += 1
	count += n - m
	print(int(count))


def calc_steps(n, m):
	steps = 0
	if n >= m:
		return n - m
	else:
		while n != m:
			if m % 2 == 0 and m > n:
				m /= 2
			else:
				m += 1
			steps += 1
		return steps
(n, m) = (int(s) for s in input().split())
print(calc_steps(n, m))


import queue
(n, m) = map(int, input().split())
que = queue.Queue()
que.put((n, 0))
d = {}
while m not in d:
	top = que.get()
	if top[0] <= 0 or top[0] >= 20000.0 + 10:
		continue
	if top[0] in d:
		continue
	d[top[0]] = top[1]
	que.put((top[0] * 2, top[1] + 1))
	que.put((top[0] - 1, top[1] + 1))
print(d[m])


import math
import sys
(a, b) = map(int, input().split())
c = 0
while a != b:
	if b <= a:
		c += a - b
		b = a
	elif b % 2 == 0:
		c += 1
		b = b // 2
	else:
		c += 1
		b += 1
print(c)


(n, m) = input().split()
n = int(n)
m = int(m)
if n >= m:
	print(n - m)
else:
	count = 0
	while n < m:
		count += 1
		n *= 2
	num = n - m
	num = bin(num)[2:]
	count2 = 0
	for i in range(count):
		if num[-1] == '1':
			count2 += 1
		num = num[:-1]
		if num == '':
			break
	if num == '':
		print(count + count2)
	else:
		print(count + count2 + int('0b' + num, 2))


from math import ceil

def Res(n, m):
	if n >= m:
		return n - m
	else:
		return 1 + m % 2 + Res(n, ceil(m / 2))
(n, m) = map(int, input().split())
print(Res(n, m))


from sys import stdin, stdout
import heapq
import cProfile
from collections import Counter, defaultdict, deque
from functools import reduce
import math

def get_int():
	return int(stdin.readline().strip())

def get_tuple():
	return map(int, stdin.readline().split())

def get_list():
	return list(map(int, stdin.readline().split()))

def maxSubArraySum(a, size):
	max_so_far = a[0]
	curr_max = a[0]
	for i in range(1, size):
		curr_max = max(a[i], curr_max + a[i])
		max_so_far = max(max_so_far, curr_max)
	return max_so_far

def solve(n, m):
	if n >= m:
		return n - m
	if m % 2:
		return 1 + solve(n, m + 1)
	return 1 + solve(n, m // 2)

def main():
	(n, m) = get_tuple()
	print(solve(n, m))
TestCases = False
if TestCases:
	for i in range(get_int()):
		main()
else:
	main()


import sys
from random import choice, randint
inp = sys.stdin.readline
out = sys.stdout.write
flsh = sys.stdout.flush
sys.setrecursionlimit(10 ** 9)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def MI():
	return map(int, inp().strip().split())

def LI():
	return list(map(int, inp().strip().split()))

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines().strip()]

def LI_():
	return [int(x) - 1 for x in inp().strip().split()]

def LF():
	return [float(x) for x in inp().strip().split()]

def LS():
	return inp().strip().split()

def I():
	return int(inp().strip())

def F():
	return float(inp().strip())

def S():
	return inp().strip()

def pf(s):
	return out(s + '\n')

def JA(a, sep):
	return sep.join(map(str, a))

def JAA(a, s, t):
	return s.join((t.join(map(str, b)) for b in a))

def main():
	(n, m) = MI()
	result = 0
	while n != m:
		if m > n:
			if m % 2 == 0:
				m //= 2
				result += 1
			else:
				m += 1
				result += 1
		else:
			m += 1
			result += 1
	pf(str(result))
main()


from collections import deque, defaultdict
from math import ceil

def min_moves(start: int, target: int) -> int:
	if start == target:
		return 0
	if start > target:
		return start - target
	half_target = ceil(target / 2)
	minmoves = 100000000
	distance = defaultdict(lambda : 10000000)
	queue = deque()
	queue.append(start)
	distance[start] = 0
	while queue:
		current_val = queue.popleft()
		if target == current_val - 1 or target == current_val * 2:
			new_move = distance[current_val] + 1
			return min(new_move, minmoves)
		elif current_val > target:
			minmoves = min(distance[current_val] + (current_val - target), minmoves)
		else:
			new_distance = distance[current_val] + 1
			if new_distance > distance[current_val * 2]:
				continue
			queue.append(current_val * 2)
			distance[current_val * 2] = min(distance[current_val] + 1, distance[current_val * 2])
			new_distance = distance[current_val] + 1
			if new_distance > distance[current_val - 1]:
				continue
			queue.append(current_val - 1)
			distance[current_val - 1] = min(distance[current_val] + 1, distance[current_val - 1])
(start, target) = [int(x) for x in input().split()]
print(min_moves(start, target))


import math, sys
from collections import Counter

def li():
	return list(map(int, sys.stdin.readline().split()))

def ls():
	return list(map(int, list(input())))

def la():
	return list(input())

def i():
	return int(input())

def isPrime(n):
	i = 2
	if n == 1:
		return False
	while i <= int(math.sqrt(n)):
		if n % i == 0:
			return False
		i = i + 1
	return True

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)
(n, m) = li()
if n >= m:
	print(n - m)
else:
	count = 0
	a = m
	while m > n:
		if m % 2 != 0:
			m = m + 1
			count = count + 1
		m = math.ceil(m / 2)
		count = count + 1
	count += n - m
	print(count)


from collections import deque
(n, m) = map(int, input().split())

def func1(n, m):
	graph = dict()
	graph[n] = [2 * n, n - 1]
	graph_dist = dict()
	graph_dist[n] = 0
	graph_dist[2 * n] = 1
	graph_dist[n - 1] = 1
	search_q = deque()
	search_q += graph[n]
	while True:
		number = search_q.popleft()
		if number == m:
			return graph_dist[number]
		elif number > m:
			graph[number] = [number - 1]
		elif number < m / 10:
			graph[number] = [number * 2]
		else:
			graph[number] = [2 * number, number - 1]
		for v in graph[number]:
			if graph_dist.get(v) is None:
				graph_dist[v] = graph_dist[number] + 1
		search_q += graph[number]
sum = 0
m_temp = m
if n < m:
	while True:
		m = m_temp
		m_temp = int(m_temp / 2 + m_temp % 2 / 2)
		sum += func1(m_temp, m)
		if m_temp / 2 < n:
			sum += func1(n, m_temp)
			break
	print(sum)
else:
	print(func1(n, m))


import sys
input = sys.stdin.readline

def solve(n, m):
	if n >= m:
		return n - m
	graph = {}
	for i in range(1, 2 * m + 1):
		graph[i] = set()
	for i in graph:
		if i - 1 in graph:
			graph[i].add(i - 1)
		if i * 2 in graph:
			graph[i].add(i * 2)
	ans = 0
	(queue, next_queue, visited) = ([n], [], set())
	while True:
		for i in queue:
			visited.add(i)
			if i == m:
				return ans
			for j in graph[i]:
				if j not in visited:
					next_queue.append(j)
		(queue, next_queue) = (next_queue, [])
		ans += 1
(n, m) = map(int, input().split(' '))
ans = solve(n, m)
print(ans)


(m, n) = map(int, input().split())
import sys
sys.setrecursionlimit(15000)
import math

def solver(m, n):
	if m >= n:
		return m - n
	if n % 2 == 0:
		return 1 + solver(m, n / 2)
	else:
		return 2 + solver(m, (n + 1) / 2)
print(int(solver(m, n)))


from collections import deque
(a, b) = map(int, input().split())

def bfs(src, target, vis):
	q = deque()
	q.append([src, 0])
	vis.add(a)
	while q:
		(curr, d) = q.popleft()
		if curr == target:
			return d
		for child in [curr - 1, curr * 2]:
			if child not in vis and child > 0 and (child < 10001):
				q.append([child, d + 1])
				vis.add(child)
	return 0
vis = set()
print(bfs(a, b, vis))


lectura = lambda : map(int, input().split())
(n, m) = lectura()
conclusion = 0
while n < m:
	conclusion += 1 + m % 2
	m = (m + m % 2) / 2
conclusion += n - m
print(int(conclusion))


import os
import sys
from io import BytesIO, IOBase

def func(a, b):
	if a >= b:
		return a - b
	elif b % 2 == 0:
		return 1 + func(a, b // 2)
	else:
		return 2 + func(a, (b + 1) // 2)

def main():
	(n, m) = map(int, input().split())
	print(func(n, m))
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


from sys import stdin, stdout
(a, b) = map(int, stdin.readline().split())
if a > b:
	print(a - b)
elif a < b:
	c = 0
	while a < b:
		if b % 2 == 0:
			b = b // 2
			c += 1
		else:
			c += 1
			b += 1
			b = b // 2
			c += 1
	c += a - b
	print(c)
else:
	print('0')


(n, m) = list(map(int, input().split()))
if n == m:
	print(0)
	exit()
x = set()
q = [(n, 0)]
s = 0
while len(q):
	w = q.pop(0)
	a = (w[0] - 1, w[1] + 1)
	b = (w[0] * 2, w[1] + 1) if w[0] < m else (w[0] - 1, w[1] + 1)
	if a[0] == m:
		print(a[1])
		break
	if b[0] == m:
		print(b[1])
		break
	if a[0] not in x and a[0] > 1:
		x.add(a[0])
		q.append(a)
	if b[0] not in x and 0 < b[0]:
		x.add(b[0])
		q.append(b)


(n, m) = map(int, input().split())
if n < m:
	import math
	c = math.ceil(math.log(m / n, 2))
	a = '{:b}'.format(n * 2 ** c - m)
	print(c + a.count('1') if len(a) < c + 2 else c + a[-c:].count('1') + int(a[:-c], 2))
else:
	print(n - m)


import sys, io, os, time
from collections import defaultdict
from collections import OrderedDict
from collections import deque
from itertools import combinations
from itertools import permutations
import bisect, math, heapq
alphabet = 'abcdefghijklmnopqrstuvwxyz'
input = sys.stdin.readline
sys.setrecursionlimit(100)
(n, m) = map(int, input().split())

def go(i):
	if i == n:
		return 0
	if n > i:
		return n - i
	if i % 2 == 0:
		return go(i // 2) + 1
	else:
		return go(i + 1) + 1
print(go(m))


from queue import Queue

def bfs(n, m):
	q = Queue()
	q.put((n, 0))
	visited = {n}
	while not q.empty():
		(value, moves) = q.get()
		if value == m:
			return moves
		for v in [value * 2, value - 1]:
			if v not in visited and 0 <= v <= 80000:
				visited.add(v)
				q.put((v, moves + 1))
	return 'NO'

def main():
	(n, m) = [int(x) for x in input().split()]
	result = bfs(n, m)
	print(result)
main()


def tb(x, y):
	presses = 0
	if x > y:
		print(x - y)
		return 0
	while y != x:
		if y < x or y % 2 == 1:
			y += 1
			presses += 1
		else:
			y = y / 2
			presses += 1
	print(presses)
	return 0
values = input().split()
n = int(values[0])
m = int(values[1])
tb(n, m)


(start, end) = list(map(int, input().split()))
if start > end:
	print(start - end)
else:
	count = 0
	while start != end:
		if not end % 2 and end > start:
			end = end // 2
		else:
			end += 1
		count += 1
	print(count)


import queue
(n, m) = map(int, input().split())
q = queue.Queue()
a = [[] for i in range(10001)]
for i in range(1, 10001):
	a[i].append(i * 2)
	a[i].append(i - 1)

def bfs(n, m):
	c = 0
	d = [-1] * 10001
	d[n] = 0
	q.put(n)
	x = -1
	while not q.empty():
		u = q.get(0)
		for i in range(len(a[u])):
			if a[u][i] <= 10000:
				if d[a[u][i]] == -1:
					d[a[u][i]] = d[u] + 1
					q.put(a[u][i])
					if a[u][i] == m:
						c = -1
						x = d[m]
						break
		if c == -1:
			break
	return d[m]
print(bfs(n, m))


(n, m) = input().strip().split()
n = int(n)
m = int(m)
time = 0
if n > m:
	time += n - m
else:
	while m - n != 0:
		if divmod(m, 2)[1] == 0 and m > n:
			m = int(m / 2)
			time += 1
		elif n >= m:
			time += n - m
			break
		else:
			m = int((m + 1) / 2)
			time += 2
print(time)


(source, target) = [int(x) for x in input().split(' ')]
rev_buf = target
steps = 0
while rev_buf != source:
	if rev_buf < source:
		rev_buf += 1
	elif rev_buf % 2 == 0:
		rev_buf /= 2
	else:
		rev_buf += 1
	steps += 1
print(steps)


import sys

def read():
	return sys.stdin.readline().strip()

def printf(a, sep=' ', end='\n'):
	sys.stdout.write(sep.join(map(str, a)) + end)

def readf():
	return [int(i) for i in read().split()]

def main():
	(n, m) = readf()
	if n > m:
		printf([n - m])
	else:
		k = m // n + 1
		dp = [10 ** 4 + 1] * (2 * (n * k) + 1)
		for i in range(n + 1):
			dp[i] = n - i
			dp[i * 2] = min(dp[i * 2], dp[i] + 1)
		for i in range(n + 1, n * k + 1):
			if i % 2 == 0:
				dp[i] = min(dp[i], dp[i // 2] + 1)
			else:
				dp[i] = min(dp[i], dp[i + 1] + 1)
			dp[i * 2] = min(dp[i * 2], dp[i] + 1)
		printf([dp[m]])
main()


n = input().split(' ')
a = int(n[0])
b = int(n[1])
c = 0
while b > a:
	if b % 2 == 0:
		b //= 2
	else:
		b += 1
	c += 1
hasil = c + a - b
print(hasil)


import math
ins = input().strip().split(' ')
(n, m) = (int(ins[0]), int(ins[1]))

def button(x, z):
	count = 0
	while x != z:
		count += 1
		if z < x:
			z += 1
		elif z % 2 == 0:
			z = int(z / 2)
		else:
			count += 1
			z = int((z + 1) / 2)
	return count
print(button(n, m))


import math
(n, m) = map(int, input().split())
if m <= n:
	print(n - m)
else:
	r = math.ceil(math.log(m / n, 2))
	left = n * 2 ** r - m
	left = int(left)
	b = 0
	for i in range(r, -1, -1):
		b = b + left // 2 ** i
		left = left % 2 ** i
	print(r + b)


import queue

def bfs(n, m):
	q = queue.Queue()
	q.put(n)
	dist[n] = 0
	while not q.empty():
		n = q.get()
		for vizinho in adj[n]:
			if dist[vizinho] > dist[n] + 1:
				dist[vizinho] = dist[n] + 1
				q.put(vizinho)
	print(dist[m])
INF = 10 ** 9
(n, m) = map(int, input().split())
adj = []
dist = []
if n >= m:
	print(n - m)
else:
	for i in range(1, (m + 2) * 2):
		adj.append([])
		dist.append(INF)
	for i in range(1, (m + 1) * 2):
		if i > 1:
			adj[i].append(i - 1)
	for i in range(1, m + 2):
		adj[i].append(i * 2)
	bfs(n, m)


def main():
	(n, m) = map(int, input().split())
	count = 0
	while m != n:
		if n > m:
			count += n - m
			break
		else:
			if m % 2:
				m += 1
			else:
				m /= 2
			count += 1
	print(int(count))
main()


(n, k) = input().split()
n = int(n)
k = int(k)
if n > k:
	print(n - k)
elif n == k:
	print(n - k)
else:
	pas = 0
	while k > n:
		if k & 1:
			k += 1
			k //= 2
			pas += 2
		else:
			k //= 2
			pas += 1
	if k < n:
		pas += n - k
	print(pas)


(n, m) = map(int, input().split())
if n >= m:
	print(n - m)
	exit(0)
q = [(n, 0)]
d = {}
while q:
	(x, y) = q.pop(0)
	if x in d:
		continue
	d[x] = True
	if x == m:
		print(y)
		break
	if 2 * x <= 2 * m:
		q.append((2 * x, y + 1))
	if x - 1 > 0:
		q.append((x - 1, y + 1))


import sys
rs = [int(i) for i in input().split()]
m = rs[0]
n = rs[1]
if m > n:
	print(m - n)
	sys.exit(0)
if m == n:
	print(0)
	sys.exit(0)
q = 0
while m < n:
	if n % 2 == 0:
		n = n // 2
	else:
		n += 1
	q += 1
if n >= m:
	print(q + (n - m))
else:
	print(q + (m - n))


(n, m) = (int(x) for x in input().split())
q = [(n, 0)]
visited = {n}
while q:
	now = q[0]
	del q[0]
	if now[0] == m:
		print(now[1])
		break
	else:
		if now[0] * 2 <= 2 * m and (not now[0] * 2 in visited):
			q.append((now[0] * 2, now[1] + 1))
			visited.add(now[0] * 2)
		if now[0] - 1 > 0 and (not now[0] - 1 in visited):
			q.append((now[0] - 1, now[1] + 1))
			visited.add(now[0] - 1)


(n, m) = map(int, input().split())
res = 0
while n != m:
	res += 1
	if n < m and m % 2 == 0:
		half = m / 2
		m -= half
	else:
		m += 1
print(res)


(n, m) = [int(x) for x in input().split()]
step = 0
if m == n or m < n:
	step = n - m
else:
	while m > n:
		if m % 2 == 0:
			m = m / 2
			step += 1
		else:
			m = (m + 1) / 2
			step += 2
	if m < n or m == n:
		step += n - m
print(int(step))


x = list(input().split())
n = int(x[0])
m = int(x[1])
total = 0
z = m
while True:
	while n > z:
		n -= 1
		total += 1
	red = 0
	while m % 2 == 0 and m > n:
		m = m / 2
		red += 1
		total += 1
	azul2 = 0
	while m % 2 == 1 and m > n:
		m += 1
		azul2 += 1
		total += 1
	azul = 0
	while m < n:
		m += 1
		azul += 1
		total += 1
	if n == m:
		break
print(total)


s = input().split()
a = int(s[1])
b = int(s[0])
otv = 0
while a != b:
	otv += 1
	if a % 2 == 0 and a > b:
		a = a / 2
	elif a % 2 == 1 and a > b:
		a = a + 1
	else:
		a = a + 1
print(otv)


g = {}
for i in range(-100, 20001):
	g[i] = []
for i in range(1, 10001):
	if 2 * i <= 10000:
		g[i] = [i - 1, 2 * i]
	else:
		g[i] = [i - 1]
(a, b) = list(map(int, input().split(' ')))
visited = [False] * 20005
dist = [100000] * 20005
x = [a]
dist[a] = 0
while x:
	a = x.pop()
	if not visited[a]:
		visited[a] = True
		x = g[a] + x
		for i in g[a]:
			dist[i] = min(dist[i], dist[a] + 1)
print(dist[b])


(n, m) = [int(i) for i in input().split(' ')]

def tow_buttons(m: int) -> int:
	return 0 if n == m else n - m if n > m else tow_buttons(m // 2) + 1 if not m % 2 else tow_buttons((m + 1) // 2) + 2
print(tow_buttons(m))


(n, m) = map(int, input().split())
if n < m:
	x = m
	c = 0
	while x != n:
		if x % 2 == 1:
			x += 1
			c += 1
		if x == n:
			break
		if x > n:
			x = x / 2
		else:
			x += 1
		c += 1
	print(c)
elif n > m:
	print(n - m)
else:
	print(0)


import math
(n, m) = map(int, input().split())
if n > m:
	print(n - m)
elif n == m:
	print(0)
else:
	count = 0
	while 1:
		if m == n:
			print(count)
			exit(0)
		if m % 2 == 0 and m > n:
			count += 1
			m = m // 2
		else:
			m += 1
			count += 1


import math
(n, m) = [int(x) for x in input().split()]
s = 0
while n < m:
	if m % 2 == 0:
		s += 1
		m = m / 2
	else:
		s += 2
		m = (m + 1) / 2
print(int(s + n - m))


def main():
	read_many = lambda type_: list(map(type_, input().split()))
	(n, m) = read_many(int)
	press = 0
	while m > n:
		m = m + 1 if m % 2 == 1 else m // 2
		press += 1
	result = press + n - m
	print(result)
main()


from sys import *
inp = lambda : stdin.readline()

def main():
	(n, m) = map(int, inp().split())
	ans = 0
	if n < m:
		while m > n:
			if m % 2 == 0:
				m //= 2
				ans += 1
			else:
				m += 1
				ans += 1
		ans += n - m
	else:
		ans += n - m
	print(ans)
main()


def solution(n, m):
	operations = 0
	while n != m:
		operations += 1
		m += 1 if m < n or m % 2 == 1 else -m // 2
	return operations
(n, m) = map(int, input().split())
print(solution(n, m))


from collections import deque

def best_path(n, m):
	queue = deque()
	visited = set()
	queue.append((n, 0))
	while queue:
		curr = queue.popleft()
		(val, steps) = (curr[0], curr[1])
		if val == m:
			return steps
		if val < 1:
			continue
		if val - 1 not in visited:
			queue.append((val - 1, steps + 1))
			visited.add(val - 1)
		if val * 2 not in visited and val < m:
			queue.append((val * 2, steps + 1))
			visited.add(val * 2)
	return -1

def main():
	(n, m) = [int(i) for i in input().split()]
	print(str(best_path(n, m)))
main()


(n, m) = map(int, input().split())
if n >= m:
	print(n - m)
else:
	(ans1, ans2, tmp_m, tmp_n) = (0, 0, m, n)
	while tmp_n < m:
		tmp_n *= 2
		ans1 += 1
	ans1 += tmp_n - m
	while tmp_m > n:
		if tmp_m & 1:
			tmp_m += 1
		else:
			tmp_m //= 2
		ans2 += 1
	ans2 += n - tmp_m
	print(min([ans1, ans2]))


import sys

def main(n, m):
	count = 0
	if m < n:
		return n - m
	while m > n:
		if m % 2 == 0:
			m /= 2
			count += 1
		else:
			m += 1
			count += 1
	return count + n - m
lines = sys.stdin.readlines()
nums = lines[0].strip().split(' ')
n = int(nums[0])
m = int(nums[1])
print(int(main(n, m)))


from collections import deque
(n, m) = map(int, input().split())
visited = {n}
d = deque([(n, 0)])
while len(d) > 0:
	(v, c) = d.popleft()
	if v == m:
		print(c)
		break
	if v > 1 and v - 1 not in visited:
		visited.add(v - 1)
		d.append((v - 1, c + 1))
	if v < m and 2 * v not in visited:
		visited.add(2 * v)
		d.append((2 * v, c + 1))


import sys
input = sys.stdin.readline

def inp():
	return int(input())

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
(n, m) = invr()
c = 0
while n != m:
	if m < n:
		m += 1
	elif m % 2 == 0:
		m /= 2
	elif m % 2 == 1:
		m = (m + 1) / 2
		c += 1
	c += 1
print(c)


(a, b) = map(int, input().split(' '))
for i in range(15):
	if a * 2 ** i >= b:
		x = 2 ** i
		y = a * 2 ** i - b
		break
tot = 0
while x != 1:
	if y % 2 == 0:
		y //= 2
		x //= 2
		tot += 1
	elif y % 2 == 1:
		y -= 1
		y //= 2
		x //= 2
		tot += 2
print(tot + y)


(n, m) = map(int, input().split())
r = 0
if n > m:
	print(n - m)
else:
	for i in range(m):
		if m % 2 == 0:
			m = m / 2
			r += 1
		else:
			m = (m + 1) / 2
			r += 2
		if n >= m:
			print(int(n - m + r))
			exit()


from collections import deque

def bfs(num):
	q = deque()
	q.append(num)
	while len(q) > 0 and q[0] < 100000.0:
		if q[0] > 0:
			if visited[q[0] - 1] == 0:
				q.append(q[0] - 1)
				visited[q[0] - 1] = 1
				graf[q[0] - 1] = min(graf[q[0]] + 1, graf[q[0] - 1])
		if q[0] <= 5000:
			if visited[q[0] * 2] == 0:
				q.append(q[0] * 2)
				visited[q[0] * 2] = 1
				graf[q[0] * 2] = min(graf[q[0]] + 1, graf[q[0] * 2])
		q.popleft()
inf = 10000000000.0
(n, m) = [int(i) for i in input().split()]
graf = [inf for i in range(int(100000.0))]
visited = [0 for i in range(int(100000.0))]
graf[n] = 0
if m >= n:
	bfs(n)
	print(graf[m])
else:
	print(n - m)


(a, b) = map(int, input().split())
ans = 0
while a < b:
	ans += 1 + b % 2
	b = (b + b % 2) // 2
print(a - b + ans)


((n, m), b) = (map(int, input().split()), 0)

def m_is_even(m):
	return m % 2 == 0
if n == m:
	print(b)
else:
	while m > n:
		b += 1
		if m_is_even(m) and m > n:
			m -= m // 2
			continue
		m += 1
	while n > m:
		b += 1
		m += 1
	print(b)


(n, m) = map(int, input().split())
if n >= m:
	print(n - m)
else:
	c = 0
	d = m
	while True:
		if d <= n:
			break
		if d % 2 == 0:
			d = d // 2
			c = c + 1
		elif d % 2 != 0:
			d = d + 1
			d = d // 2
			c = c + 2
	c = c + (n - d)
	print(c)


from collections import deque

def dfs(n, m):
	fila = deque([n])
	distancias = {n: 0}
	menorDistancia = 10000000
	while len(fila) > 0:
		vertice = fila.popleft()
		vesquerda = 2 * vertice
		if vesquerda <= 2 * m and distancias.get(vesquerda) == None:
			distancias[vesquerda] = distancias[vertice] + 1
			fila.append(vesquerda)
			if vesquerda == m:
				menorDistancia = min(menorDistancia, distancias[vesquerda])
				break
		vdireita = vertice - 1
		if vdireita > 0 and distancias.get(vdireita) == None:
			distancias[vdireita] = distancias[vertice] + 1
			fila.append(vdireita)
			if vdireita == m:
				menorDistancia = min(menorDistancia, distancias[vdireita])
				break
	return menorDistancia
entrada = input().split()
n = int(entrada[0])
m = int(entrada[1])
print(dfs(n, m))


import bisect
import copy
import sys
import time
EPS = sys.float_info.epsilon
LENGTH = 10
matrix = [[] for i in range(LENGTH)]
array = [0] * 1001

class Edge:
	__slots__ = ['__vertex_to', '__weight']

	def __init__(self, vertex_to: object, weight: float):
		self.__vertex_to = vertex_to
		self.__weight = weight
	vertex_to = property(lambda self: self.__vertex_to)
	weight = property(lambda self: self.__weight)

class Graph:
	__slots__ = ['__adj']
	(__WHITE_NODE, __GRAY_NODE, __BLACK_NODE, __NULL_PARENT) = (0, 1, 2, None)

	def __init__(self):
		self.__adj = dict()

	def add_edge(self, vertex_from: object, vertex_to: object, weight: float=0.0):
		edge = Edge(vertex_to, weight)
		if vertex_to not in self.__adj:
			self.__adj[vertex_to] = []
		if vertex_from not in self.__adj:
			self.__adj[vertex_from] = [edge]
		else:
			self.__adj[vertex_from].append(edge)
	adj = property(lambda self: copy.deepcopy(self.__adj))
	WHITE_NODE = property(classmethod(lambda cls: cls.__WHITE_NODE))
	GRAY_NODE = property(classmethod(lambda cls: cls.__GRAY_NODE))
	BLACK_NODE = property(classmethod(lambda cls: cls.__BLACK_NODE))
	NULL_PARENT = property(classmethod(lambda cls: cls.__NULL_PARENT))

class BFS:
	__slots__ = ['__adj', '__used', '__parent']

	def __init__(self, graph: Graph):
		self.__parent = dict()
		self.__used = dict()
		self.__adj = graph.adj

	def search_path(self, vertex_from, vertex_to) -> list:
		path = []
		if vertex_to not in self.__parent:
			return path
		while vertex_to != vertex_from:
			path.append(vertex_to)
			vertex_to = self.__parent[vertex_to]
		path.append(vertex_to)
		return path

	def bypass(self, vertex: object):
		self.__parent.clear()
		self.__used.clear()
		queue = [vertex]
		for key in self.__adj:
			self.__used[key] = Graph.WHITE_NODE
			self.__parent[key] = Graph.NULL_PARENT
		self.__used[vertex] = Graph.BLACK_NODE
		while len(queue) > 0:
			vertex = queue.pop(0)
			for edge in self.__adj[vertex]:
				if self.__used[edge.vertex_to] == Graph.WHITE_NODE:
					self.__used[edge.vertex_to] = Graph.BLACK_NODE
					queue.append(edge.vertex_to)
					self.__parent[edge.vertex_to] = vertex
(n, m) = map(int, input().split())
graph = Graph()
for i in range(1, 10010):
	graph.add_edge(i + 1, i)
	graph.add_edge(i, i * 2)
bfs = BFS(graph)
bfs.bypass(n)
print(len(bfs.search_path(n, m)) - 1)


from math import ceil
inputs = list(map(int, input().split()))
n = inputs[0]
m = inputs[1]
buttons = 0
halfway = ceil(m / 2)
while m > n:
	if m % 2 == 1:
		m += 1
	else:
		m //= 2
	buttons += 1
buttons += n - m
print(buttons)


(n, k) = map(int, input().split())
ans = 0
while k != n:
	while k < n:
		ans += 1
		k += 1
	while k > n:
		if k % 2 == 0:
			k //= 2
			ans += 1
		else:
			ans += 1
			k += 1
print(ans)


(n, m) = map(int, input().split())
if n >= m:
	print(n - m)
else:
	steps = 0
	while True:
		if m <= n:
			break
		if m % 2 == 0:
			m = m // 2
			steps += 1
		else:
			m += 1
			steps += 1
	if m == n:
		print(steps)
	else:
		print(steps + (n - m))


def main():
	(n, m) = input().split()
	(n, m) = (int(n), int(m))
	a = 0
	while m > n:
		if m % 2:
			m += 1
		else:
			m //= 2
		a += 1
	print(a + n - m)
main()


def f(a, b):
	if b <= a:
		return a - b
	return 1 + b % 2 + f(a, (b + 1) // 2)
(a, b) = map(int, input().split())
print(f(a, b))


(n, w) = map(int, input().split())
t = 0
while n != w:
	t += 1
	w += 1 if w < n or w & 1 else -w // 2
print(t)


from sys import stdin
from collections import deque

def solve():
	(n, m) = [int(i) for i in stdin.readline().split()]
	q = deque()
	q.append([0, n])
	mx = float('inf')
	st = set()
	ans = 1
	while q:
		(ans, n) = q.popleft()
		if n < 0:
			continue
		if n in st:
			continue
		if m == n:
			return min(ans, mx)
		else:
			st.add(n)
			if n * 2 > m:
				mx = min(mx, 1 + ans + n * 2 - m)
			else:
				q.append([ans + 1, n * 2])
			q.append([ans + 1, n - 1])
	return mx
print(solve())


(a, b) = map(int, input().split())
c = 0
while True:
	if b % 2 == 0 and b > a:
		c += 1
		b = b // 2
	else:
		c += 1
		b += 1
	if b == a:
		break
print(c)


s = input()
s = s.split()
n = int(s[0])
m = int(s[1])
graph = [[] for i in range(0, 20001)]
count = 1
for i in graph[1:]:
	if count <= 10000:
		i.append(count * 2)
	if count > 1:
		i.append(count - 1)
	count += 1
visited = [False for i in range(0, 40004)]
stk = [n]
dist = 0
while True:
	dist += 1
	stk_temp = []
	for i in stk:
		for j in graph[i]:
			if j == m:
				print(dist)
				quit()
			elif visited[j] == False:
				stk_temp.append(j)
				visited[j] = True
	stk = stk_temp


a = list(map(int, input().split()))
if a[1] <= a[0]:
	print(a[0] - a[1])
else:
	count = 0
	while True:
		if a[1] <= a[0]:
			count += a[0] - a[1]
			break
		elif a[1] % 2 == 0:
			a[1] //= 2
			count += 1
		else:
			a[1] += 1
			count += 1
	print(count)


(n, m) = map(int, input().split())
res = 0
if n >= m:
	res = n - m
elif n < m:
	while m > n:
		if m % 2 == 0:
			m = m // 2
			res += 1
		elif m % 2 == 1:
			m = m + 1
			res += 1
		if m < n:
			res = res + (n - m)
			break
print(res)


import sys
nums = list(map(int, sys.stdin.readline().split()))
count = 0
while nums[0] < nums[1]:
	if nums[1] % 2 == 0:
		nums[1] //= 2
	else:
		nums[1] += 1
	count += 1
print(count + nums[0] - nums[1])


(n, m) = map(int, input().split())
if n > m:
	print(n - m)
else:
	j = 0
	while n != m:
		if m % 2 == 0:
			m /= 2
			j += 1
		else:
			m += 1
			j += 1
		if m < n:
			j += n - m
			break
	print(int(j))


line = input().split()
n = int(line[0])
m = int(line[1])
a = []
a += [n]
visit = [0] * 10001
while len(a) > 0:
	if a[0] == m:
		print(visit[a[0]])
		break
	else:
		temp = a[0] * 2
		if temp < 10001 and visit[temp] == 0:
			a += [temp]
			visit[temp] = visit[a[0]] + 1
		temp = a[0] - 1
		if temp > 0 and visit[temp] == 0:
			a += [temp]
			visit[temp] = visit[a[0]] + 1
		a.pop(0)


inp = input().split(' ')
n = int(inp[0])
m = int(inp[1])
move = 0
while True:
	if n >= m:
		print(move + (n - m))
		exit(0)
	if m % 2 == 0:
		m //= 2
		move += 1
	else:
		m = (m + 1) // 2
		move += 2


def num_steps(given, ideal):
	steps = 0
	while given < ideal:
		if ideal % 2 == 0:
			ideal = ideal / 2
		else:
			ideal += 1
		steps += 1
	return int(steps + (given - ideal))
inputs = [int(num) for num in input().split()]
n = inputs[0]
m = inputs[1]
result = num_steps(n, m)
print(result)


(ori, fin) = input().split(' ')
ori = int(ori)
fin = int(fin)
myset = set()
myset.add(ori)
ret = -1
finished = False
visited = set()
while not finished and myset:
	ret += 1
	newset = set()
	for num in myset:
		if num == fin:
			finished = True
		if num < fin and 2 * num not in visited:
			visited.add(2 * num)
			newset.add(2 * num)
		if num > 1 and num - 1 not in visited:
			visited.add(num - 1)
			newset.add(num - 1)
	myset = newset
print(ret)


from collections import deque
(n, m) = map(int, input().split())
MAX = float('inf')
visited = set()

def bfs():
	q = deque()
	dist = 0
	q.append((n, dist))
	while q:
		(curr, dist) = q.popleft()
		if curr == m:
			return dist
		if curr > 1 and curr - 1 not in visited:
			q.append((curr - 1, dist + 1))
		if curr < m and curr * 2 not in visited:
			q.append((curr * 2, dist + 1))
		visited.add(curr)
		dist += 1
	return -1
print(bfs())


(n, m) = map(int, input().split())
Q = []
sz = 0
inf = 1000000009
Q.append(n)
D = [inf] * 20004
D[n] = 0
while sz < len(Q):
	x = Q[sz]
	sz += 1
	if x + x <= 20000 and D[x + x] == inf:
		D[x + x] = D[x] + 1
		Q.append(x + x)
	if x - 1 >= 1 and D[x - 1] == inf:
		D[x - 1] = D[x] + 1
		Q.append(x - 1)
print(D[m])


import sys
initial = sys.stdin.read().split(' ')
start = int(initial[0])
end = int(initial[1])
queue = []
dic = {}
m = start
count = 0
while m < end:
	m *= 2
	count = count + 1
count = m - end + count
if start > end:
	print(start - end)
else:
	queue.append((start, 0))
	while queue[0][0] != end:
		if queue[0][1] > count:
			break
		if queue[0][0] - 1 >= 0 and queue[0][0] <= m and (not queue[0][0] - 1 in dic):
			queue.append((queue[0][0] - 1, queue[0][1] + 1))
			dic[queue[0][0] - 1] = queue[0][1]
		if queue[0][0] * 2 <= m and (not queue[0][0] * 2 in dic):
			queue.append((queue[0][0] * 2, queue[0][1] + 1))
			dic[queue[0][0] * 2] = queue[0][1]
		queue.pop(0)
	print(queue[0][1])


(n1, n2) = map(int, input().split())
a = 0
while n1 != n2:
	a += 1
	n2 += 1 if n2 < n1 or n2 & 1 else -n2 // 2
print(a)


import sys
(n, m) = map(int, sys.stdin.readline().split())
s = set()
s.add(n)
s_total = set()
ans = 0
while s:
	ans += 1
	s_total |= s
	s = {2 * i for i in s} | {i - 1 for i in s if i > 1}
	s = s - s_total
	s1 = {i for i in s if i <= m}
	s2 = s - s1
	s = s1
	if s2:
		s.add(min(s2))
	if s:
		if m in s:
			print(ans)
			break
	else:
		print(-1)
		break


(n, m) = input().split()
n = int(n)
m = int(m)
x = 0
while n != m:
	x += 1
	if m < n or m & 1 == 1:
		m += 1
	else:
		m = m // 2
print(x)


def find_path_count(x, y):
	if x == y:
		return 0
	paths = {x}
	count = x * y
	max_t = 2 * y
	cur_i = -1
	while True:
		new_paths = set()
		cur_i += 1
		for t in paths:
			temps = (t - 1, t * 2)
			for temp in temps:
				if temp == y:
					return cur_i + 1
				if temp not in paths:
					if temp > 1:
						if temp > y:
							count = min(count, temp - y + cur_i + 1)
							continue
						new_paths.add(temp)
		paths = new_paths
		if cur_i >= count:
			return count
(x, y) = map(int, input().split(' '))
print(find_path_count(x, y))


import collections

def press(start, end):

	def _explore(foot, exp, nex, nex_step):
		if nex not in foot:
			foot.add(nex)
			exp.append((nex, nex_step))
	footprint = set([start])
	toexplore = collections.deque([(start, 0)])
	while toexplore:
		(cur, step) = toexplore.popleft()
		if cur == end:
			return step
		sub_nex = cur - 1
		_explore(footprint, toexplore, sub_nex, step + 1)
		if cur < end:
			mul_nex = cur * 2
			_explore(footprint, toexplore, mul_nex, step + 1)
(n, m) = map(int, input().split())
print(press(n, m))


def eh_par(x):
	return numero_m % 2 == 0
(numero_n, numero_m) = map(int, input().split())
aux = 0
while numero_m > numero_n:
	if eh_par(numero_m):
		numero_m = numero_m // 2
	else:
		numero_m += 1
	aux += 1
diferenca = numero_n - numero_m
min_apertos = aux + diferenca
print(min_apertos)


import queue
t = [int(i) for i in input().split()]
(n, m) = (t[0], t[1])
q = queue.Queue()
q.put((n, 0))
s = set()
while True:
	t = q.get()
	s.add(t[0])
	if t[0] == m:
		print(t[1])
		break
	else:
		if t[0] - 1 >= 1 and t[0] - 1 not in s:
			q.put((t[0] - 1, t[1] + 1))
		if t[0] < m and t[0] * 2 not in s:
			q.put((t[0] * 2, t[1] + 1))


from collections import deque
from sys import stdin
arr = [int(x) for x in stdin.readline().split()]
(start, target) = arr

class Node:

	def __init__(self, val, dist):
		self.val = val
		self.dist = dist
visited_nodes = set()
moves = [1, 2]
queue = deque([Node(start, 0)])
while queue != []:
	cur_node = queue.popleft()
	if cur_node.val in visited_nodes:
		continue
	visited_nodes.add(cur_node.val)
	if cur_node.val == target:
		print(cur_node.dist)
		break
	if cur_node.val < 0:
		continue
	for i in range(len(moves)):
		if i == 0:
			queue.append(Node(cur_node.val - 1, cur_node.dist + 1))
		else:
			if cur_node.val > target:
				break
			queue.append(Node(cur_node.val * 2, cur_node.dist + 1))


R = lambda : map(int, input().split())
(n, m) = R()
if n >= m:
	print(n - m)
	exit()
cnt = 0
while n != m:
	if n > m:
		m += 1
	elif not m % 2:
		m //= 2
	else:
		m += 1
	cnt += 1
print(cnt)


(m, n) = [int(i) for i in input().split()]

def d(begin, end):
	if begin == end:
		return 0
	if begin == end + 1:
		return 1
	if end % 2 == 0 and end // 2 == begin:
		return 1
	if begin > end:
		return begin - end
	if end % 2 == 0:
		return d(begin, end // 2) + 1
	return d(begin, end + 1) + 1
print(d(m, n))


from sys import stdin
(n, m) = map(int, stdin.readline().rstrip().split(' '))
c = 0
while m != n:
	c += 1
	if m % 2 == 1 or m < n:
		m += 1
	elif m > n and (not m % 2):
		m = m // 2
print(c)


(n, m) = map(int, input().split())
ans = 0
while m > n:
	m = m // 2 if not m % 2 else m + 1
	ans += 1
print(abs(n - m) + ans)


(n, m) = map(int, input().split())
print(min((i + ((n << i) - m >> i) + bin(((n << i) - m) % (1 << i)).count('1') for i in range(50) if n << i >= m)))


import sys
from collections import deque

def twoButtons(firstNum, secondNum):
	que = deque()
	visited = {firstNum}
	que.append((firstNum, 0))
	while que:
		data = que.popleft()
		num = data[0]
		count = data[1]
		if num == secondNum:
			print(count)
			break
		else:
			if num < secondNum and num * 2 not in visited:
				visited.add(num * 2)
				que.append((num * 2, count + 1))
			if num > 1 and num - 1 not in visited:
				visited.add(num - 1)
				que.append((num - 1, count + 1))

def main():
	nums = input().split()
	return twoButtons(int(nums[0]), int(nums[1]))
main()


def twoButton():
	import sys
	data = sys.stdin.read()
	data = data.split(' ')
	n = int(data[0])
	m = int(data[1])
	if n == m:
		return 0
	elif m < n:
		return n - m
	else:
		count = 0
		while n < m:
			if m % 2 == 0:
				m = m / 2
				count += 1
			else:
				m += 1
				count += 1
		while n > m:
			m += 1
			count += 1
		return count
print(twoButton())


from collections import deque
(n, m) = map(int, input().split())
q = deque([(0, n)])
vis = [0] * 20001
vis[n] = 1
while 1:
	(dis, idx) = q.popleft()
	if idx == m:
		print(dis)
		exit()
	if idx < m and (not vis[idx << 1]):
		vis[idx << 1] = 1
		q.append((dis + 1, idx << 1))
	if idx > 1 and (not vis[idx - 1]):
		vis[idx - 1] = 1
		q.append((dis + 1, idx - 1))


(n, m) = map(int, input().split())
if n >= m:
	print(n - m)
else:
	a = set()
	a.add(n)
	ans = 0
	while m not in a:
		b = set()
		for i in a:
			if i - 1 >= n / 3:
				b.add(i - 1)
			if 2 * i < 2 * m:
				b.add(2 * i)
		ans += 1
		a = b.difference(a)
	print(ans)


def getVals(type=str):
	return list(map(type, input().split()))

def solve(x, y):
	if x >= y:
		return x - y
	ans = 0
	while y != x:
		if x < y:
			if y & 1:
				y += 1
			else:
				y >>= 1
		else:
			y += 1
		ans += 1
	return ans
(x, y) = getVals(int)
print(solve(x, y))


(n, m) = map(int, input().split())
k = max(n, m)
a = [-1] * (k * 3)
b = [0] * (k * 4)
d = [0] * (k * 4)
l = 1
b[0] = n
i = 0
a[n] = 0
while i < l:
	cur = b[i]
	j = cur * 2
	if j < m * 2:
		if a[j] == -1:
			b[l] = j
			d[l] = d[i] + 1
			a[j] = d[l]
			l += 1
	j = cur - 1
	if j >= 0:
		if a[j] == -1:
			b[l] = j
			d[l] = d[i] + 1
			a[j] = d[l]
			l += 1
	i += 1
print(a[m])


(n, m) = [int(x) for x in input().split()]
nb_steps = 0
copy_m = m
double = {1}
while copy_m != 1:
	copy_m = int((copy_m + 1) / 2)
	double.add(copy_m)
while n != m:
	nb_steps += 1
	if n in double:
		n = 2 * n
	else:
		n -= 1
print(nb_steps)


(n, m) = map(int, input().split())
if n >= m:
	print(n - m)
else:
	dp = [float('inf')] * (2 * (m + 1))
	dp[n] = 0
	i = n - 1
	while i >= 0:
		dp[i] = dp[i + 1] + 1
		i -= 1
	for i in range(1, m + 1):
		dp[2 * i] = min(dp[2 * i], dp[i] + 1)
		if dp[2 * i - 1] == float('inf'):
			dp[2 * i - 1] = dp[2 * i] + 1
	print(dp[m])


import sys
import math

def fun(n, m, cnt):
	if m <= n:
		cnt += n - m
		print(cnt)
	elif m % 2 == 0:
		cnt += 1
		fun(n, m // 2, cnt)
	elif m % 2 != 0:
		cnt += 1
		fun(n, m + 1, cnt)
cnt = 0
(n, m) = map(int, input().split())
fun(n, m, cnt)


(n, m) = input().split()
n = int(n)
m = int(m)
bfs = []
tmp = [m]
bfs.append(tmp)
res = -1
i = 0
while True:
	tmp = []
	maior = 0
	for j in bfs[i]:
		if j == n:
			res = i
			break
		if j > maior:
			maior = j
		if j % 2 == 0:
			tmp.append(j / 2)
		else:
			tmp.append(j + 1)
	if res != -1:
		break
	elif maior < n:
		res = i + n - maior
		break
	bfs.append(tmp)
	i += 1
print(int(res))


(n, m) = input().split()
(n, m) = (int(n), int(m))
x = m
Sum = 0
if n >= m:
	print(n - m)
else:
	v = 0
	for i in range(0, 15):
		m = m / 2
		v = v + 1
		if m <= n:
			break
	if m == n:
		print(v)
	elif m == int(m):
		a = n - m
		print(int(a + v))
	else:
		m = x
		a = 0
		for j in range(0, 15):
			m = m / 2
			if m == int(m):
				if m <= n:
					break
				continue
			else:
				m = int(m) + 1
				a = a + 1
				if m <= n:
					break
		if m == n:
			Sum = j + a + 1
		else:
			b = n - int(m) + 1
			Sum = j + a + b
		print(Sum)


(a, b) = [int(x) for x in input().split()]
count = 0
big = b
small = a
while big > small:
	count += 1
	if big % 2 == 0:
		big /= 2
	else:
		big += 1
ans = count + (small - big)
print(int(ans))


(n, m) = map(int, input().split())
if n > m:
	print(n - m)
	exit()
(r, c) = (0, float('inf'))
while m != 1 and m != n:
	if m % 2:
		r += 1
		m += 1
	else:
		r += 1
		m //= 2
	if m < n:
		c = min(c, r + n - m)
if m == n:
	print(r)
else:
	print(c)


(n, m) = [int(n) for n in input().split()]
if m == n:
	print(0)
	exit()
h = []
e = (n, 0)
h.append(e)
res = 0
while n != m:
	if m < n:
		m += 1
		res += 1
		continue
	if m % 2 == 0:
		m /= 2
		res += 1
		continue
	else:
		m += 1
		m /= 2
		res += 2
print(res)


takeInput = input()
(N, M) = [int(x) for x in takeInput.split(' ')]
short = 0

def func(n, m):
	global short
	if n == m:
		return short
	if n > m:
		short = short + n - m
		return short
	short += 1
	if m % 2 == 0:
		return func(n, m / 2)
	else:
		return func(n, m + 1)
print(int(func(N, M)))


from math import log

class Noeud:

	def __init__(self, d):
		self.donnee = d
		self.next = None

	def getDonnee(self):
		return self.donnee

	def setDonnee(self, d):
		self.donnee = d

	def getNext(self):
		return self.next

	def setNext(self, n):
		self.next = n

class ListeChainee:

	def __init__(self):
		self.tete = None
		self.queue = None
		self.size = 0

	def __radd__(self, e):
		if isinstance(e, ListeChainee):
			return self.concat_copy(e)
		n = Noeud(e)
		if self.queue == None:
			self.queue = n
		else:
			n.setNext(self.tete)
		self.tete = n
		self.size += 1
		return self

	def __add__(self, e):
		if isinstance(e, ListeChainee):
			return self.concat_copy(e)
		n = Noeud(e)
		if self.queue == None:
			self.tete = n
		else:
			self.queue.next = n
		self.queue = n
		self.size += 1
		return self

	def supprimertete(self):
		cur = self.tete
		if cur != None:
			x = cur.getDonnee()
			self.tete = cur.getNext()
			if self.tete == None:
				self.queue = None
			return x
		return None

	def supprimer(self, e):
		cur = self.tete
		pr = None
		while cur != None:
			if cur.getDonnee() == e:
				if pr == None:
					self.tete = cur.getNext()
				else:
					pr.setNext(cur.getNext())
				self.size -= 1
				return
			pr = cur
			cur = cur.getNext()
(n, m) = map(int, input().split())
p = 0
e = set()
f = ListeChainee()
f + [n, 0]
while 1:
	x = f.supprimertete()
	if x[0] == m:
		break
	if x[0] not in e:
		e.add(x[0])
	else:
		continue
	if x[0] < m:
		f + [2 * x[0], x[1] + 1]
	if x[0] >= 0:
		f + [x[0] - 1, x[1] + 1]
print(x[1])


p = input()
p = p.split()
n = int(p[0])
m = int(p[1])
c = 0
if m > n:
	a = 0
	b = n
	c = m
	while c > b:
		b = b * 2
		a += 1
	while b > c:
		b -= 1
		a += 1
	d = 0
	e = n
	f = m
	while f > e:
		if f % 2 != 0:
			f = f + 1
			d += 1
		f = f // 2
		d += 1
	while f < e:
		e -= 1
		d += 1
	c = min(a, d)
if m < n:
	while m < n:
		n -= 1
		c += 1
print(c)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def fact(x):
	if x == 0:
		return 1
	else:
		return x * fact(x - 1)

def lower_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] >= num:
			answer = middle
			end = middle - 1
		else:
			start = middle + 1
	return answer

def upper_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] <= num:
			answer = middle
			start = middle + 1
		else:
			end = middle - 1
	return answer

def abs(x):
	return x if x >= 0 else -x

def binary_search(li, val, lb, ub):
	ans = 0
	while lb <= ub:
		mid = (lb + ub) // 2
		if li[mid] > val:
			ub = mid - 1
		elif val > li[mid]:
			lb = mid + 1
		else:
			ans = 1
			break
	return ans

def sieve_of_eratosthenes(n):
	ans = []
	arr = [1] * (n + 1)
	(arr[0], arr[1], i) = (0, 0, 2)
	while i * i <= n:
		if arr[i] == 1:
			j = i + i
			while j <= n:
				arr[j] = 0
				j += i
		i += 1
	for k in range(n):
		if arr[k] == 1:
			ans.append(k)
	return ans
from math import *
for _ in range(1):
	(n, m) = map(int, input().split())
	cnt = 0
	while n != m:
		if m < n:
			m += 1
		elif m % 2 == 0:
			m //= 2
		else:
			m += 1
		cnt += 1
	print(cnt)


(m, n) = map(int, input().split())
resp = 0
if m > n:
	resp = m - n
else:
	while n - m != 0:
		if n % 2 == 0 and n > m:
			n /= 2
			resp += 1
		else:
			if m >= n:
				resp += m - n
				break
			n = (n + 1) / 2
			resp += 2
print(int(resp))


import sys
from collections import deque
inputs = sys.stdin.read().split()
start = int(inputs[0])
goal = int(inputs[1])

def func(start, goal):
	if start == goal:
		return 0
	if goal < start:
		return start - goal
	if goal % 2 == 0:
		return 1 + func(start, goal // 2)
	else:
		return 1 + func(start, goal + 1)
print(func(start, goal))


import sys
input = sys.stdin.readline
(n, m) = map(int, sys.stdin.readline().split())
res = 0
while m != n:
	if m % 2 == 1 or m < n:
		m += 1
	else:
		m = m // 2
	res += 1
print(res)


def pops():
	global head
	head = head + 1
	return q[head - 1]
head = 0
(n, m) = map(int, input().split())
q = [n]
d = {n: 0}
while q:
	n = q.pop(0)
	j = n * 2
	k = n - 1
	if d.get(j, -1) == -1 and j > -1 and (j <= 20001):
		d[j] = d[n] + 1
		q.append(j)
	if d.get(k, -1) == -1 and k > -1 and (k <= 20001):
		d[k] = d[n] + 1
		q.append(k)
print(d[m])


numbers = input().split()
numbers = [int(x) for x in numbers]
steps = 0
while numbers[0] != numbers[1]:
	if numbers[0] == numbers[1]:
		print(steps)
		break
	if numbers[1] % 2 == 1:
		numbers[1] += 1
		steps += 1
	while numbers[0] < numbers[1] and numbers:
		if numbers[1] % 2 == 1:
			numbers[1] += 1
			steps += 1
		numbers[1] /= 2
		steps += 1
	while numbers[0] > numbers[1]:
		numbers[0] -= 1
		steps += 1
print(steps)


import collections
visited = [False] * 100001
d = [0] * 100001
(n, m) = map(int, input().split())
q = collections.deque([n])
visited[n] = True
while q:
	front = q.popleft()
	if not visited[2 * front] and 2 * front <= m * 2:
		visited[2 * front] = True
		q.append(2 * front)
		d[front * 2] = d[front] + 1
	if not visited[front - 1] and front - 1 >= 0:
		visited[front - 1] = True
		q.append(front - 1)
		d[front - 1] = d[front] + 1
	if visited[m]:
		break
print(d[m])


(a, b) = list(map(int, input().split()))
i = 0
while a != b:
	if a > b:
		b += 1
		i += 1
	elif b % 2 == 0:
		b = b // 2
		i += 1
	else:
		b += 1
		i += 1
print(i)


def findit(n, m):
	if n == m:
		print(0)
		return
	if n > m:
		print(n - m)
		return
	a = [-1] * (2 * m)
	q = [n]
	a[n] = 0
	while True:
		nextone = q.pop(0)
		if nextone == m:
			print(a[nextone])
			return
		howmany = a[n]
		subone = nextone - 1
		multtwo = nextone * 2
		if subone > 0 and a[subone] == -1:
			q.append(subone)
			a[subone] = a[nextone] + 1
		if multtwo < 2 * m:
			q.append(multtwo)
			a[multtwo] = a[nextone] + 1
listone = input().split()
n = int(listone[0])
m = int(listone[1])
findit(n, m)


(start, end) = input().split()
start = int(start)
end = int(end)
counter = 0
if end < start:
	print(int(min(start - 1, start - end)))
else:
	end_new = end
	while end_new > start:
		if end_new % 2 != 0:
			end_new = end_new + 1
			counter += 1
		else:
			end_new = end_new / 2
			counter += 1
			if end_new < start:
				counter += min(start - 1, start - end_new) - 1
	if end_new != start:
		start -= 1
		counter += 1
	print(int(counter))


def solve(n, m):
	count = 0
	while m != n:
		count += 1
		if m > n and m % 2 == 0:
			m /= 2
		else:
			m += 1
	print(count)
x = tuple(map(int, input().rstrip().split()))
solve(x[0], x[1])


(n, m) = map(int, input().split())
d = {}
d[n] = 0
unvisited = [n]
finished = False
while m not in d and unvisited:
	n = unvisited[0]
	del unvisited[0]
	if n > 1 and n - 1 not in d:
		d[n - 1] = d[n] + 1
		unvisited += [n - 1]
	if n < m and n * 2 not in d:
		d[n * 2] = d[n] + 1
		unvisited += [n * 2]
print(d[m])


(start, end) = map(int, input().split())
step_list = [0] * (10000 * 3)
queue = [start]
for i in queue:
	if i == end:
		break
	else:
		if i > 1:
			if step_list[i - 1] == 0:
				step_list[i - 1] = step_list[i] + 1
				queue.append(i - 1)
		if i < 10000:
			if step_list[i * 2] == 0:
				step_list[i * 2] = step_list[i] + 1
				queue.append(i * 2)
print(step_list[end])


(n, m) = map(int, input().split())
d = []
a = []
count = 0
a.append(n)
if m < n:
	print(n - m)
else:
	while 1:
		b = []
		count = count + 1
		for i in a:
			if i not in d:
				d.append(i)
				if i <= m:
					if 2 * i - m <= 100:
						b.append(2 * i)
				if i - 1 > 0:
					b.append(i - 1)
		if m in b:
			break
		a = b
	print(count)


import sys
(n, m) = (int(i) for i in sys.stdin.readline().split())
factor_count = 0
factor = 1
to_add = 0
while n < m:
	n *= 2
	factor *= 2
	factor_count += 1
to_add_total = 0
to_add = n - m
temp_factor = factor
while to_add > 0 and temp_factor > 0:
	to_add_total += to_add // temp_factor
	to_add -= temp_factor * (to_add // temp_factor)
	temp_factor //= 2
to_add_total += to_add
print(factor_count + to_add // factor + to_add_total)


import queue

def bfs(m, n):
	if m <= n:
		return n - m
	dis = {m: 0}
	team = queue.Queue()
	team.put(m)
	while not n in dis:
		m = team.get()
		dis[m + 1] = dis[m] + 1
		team.put(m + 1)
		if m % 2 or m // 2 in dis:
			continue
		dis[m // 2] = dis[m] + 1
		team.put(m // 2)
	return dis[n]
(n, m) = input().split()
print(bfs(int(m), int(n)))


class Node:

	def __init__(self, value, level):
		self.value = value
		self.level = level

def run():
	nums = [eval(n) for n in input().split()]
	start = Node(nums[0], 0)
	end = nums[1]
	count = 0
	queue = [start]
	visited = {}
	while len(queue) != 0:
		node = queue.pop(0)
		if node.value == end:
			count = node.level
			break
		if node.value <= 0 or node.value in visited:
			continue
		visited[node.value] = True
		if node.value < end:
			double = Node(node.value * 2, node.level + 1)
			queue.append(double)
		minus = Node(node.value - 1, node.level + 1)
		queue.append(minus)
	print(count)
run()


import sys
sys.setrecursionlimit(10000)

def insertion(G, A):
	while A != []:
		s = A[0][0]
		i = A[0][1]
		del A[0]
		if s > 1 and (not s - 1 in G.keys() or G[s - 1] > i):
			G[s - 1] = i
			A = A + [[s - 1, i + 1]]
		if 2 * s <= 10000 and (not 2 * s in G.keys() or G[2 * s] > i):
			G[2 * s] = i
			A = A + [[2 * s, i + 1]]
	return G
(n, m) = map(int, input().split())
G = dict()
G[n] = 0
A = [[n, 1]]
G = insertion(G, A)
print(G[m])


def Cal_Num(a, b):
	if b % 2 != 0:
		aim = b + 1
		steps = 1
	else:
		aim = b
		steps = 0
	avg = aim // 2
	if a >= avg:
		steps += a - avg
	else:
		steps += Cal_Num(a, avg)
	return steps + 1
(n, m) = map(int, input().split())
if n >= m:
	print(n - m)
	exit()
print(Cal_Num(n, m))