https://www.acmicpc.net/problem/1697
import sys
from collections import deque
input = sys.stdin.readline
def bfs(v):
q = deque()
q.append(v)
visited[v] = 0
while q:
v = q.popleft()
if v == end:
print(visited[end])
break
a, b, c = v-1, v+1, v*2
if 0 <= a < 100001 and visited[a] == -1:
visited[a] = visited[v] + 1
q.append(a)
if 0 <= b < 100001 and visited[b] == -1:
visited[b] = visited[v] + 1
q.append(b)
if 0 <= c < 100001 and visited[c] == -1:
visited[c] = visited[v] + 1
q.append(c)
start, end = map(int, input().split())
visited = [-1 for _ in range(100001)]
bfs(start)