https://www.acmicpc.net/problem/1697
import sys
sys.setrecursionlimit(10**6)
from collections import deque
def bfs(a):
q=deque()
q.append((a,0))
check[a]=1
while len(q)>0:
v0,v1=q.popleft()
if v0==k:
print(v1)
return
if 2*v0<=100000 and check[2*v0]==0:
check[2*v0]=1
q.append((2*v0,v1+1))
if v0+1<=100000 and check[v0+1]==0:
check[v0+1]=1
q.append((v0+1,v1+1))
if v0-1>=0 and check[v0-1]==0:
check[v0-1]=1
q.append((v0-1,v1+1))
n,k=map(int,input().split())
check=[0]*100001
bfs(n)