from collections import deque
def bfs(n):
global count
while q:
x,count = q.popleft()
if x ==m :
return -1
#count의 위치가 중요하다.
count = count +1 #그래프 BFS 탐색시에 깊이마다 level을 구할수있게 해주는 방법은
if 0<= x-1 <=100000 and x-1 not in visited:
q.append([x-1,count]) # 큐에 count를 저장하고 pop하는 것이다.
visited.append(x-1)
if 0<= x+1 <=100000 and x+1 not in visited:
q.append([x+1,count])
visited.append(x+1)
if 0<= x *2 <=100000 and x*2 not in visited:
q.append([x*2,count])
visited.append(x*2)
n,m = map(int,input().split())
q = deque()
visited = []
count = 0
q.append([n,count])#애초에 큐에 시작노드와 카운트를 저장하면서간다.
visited.append(n)
bfs(n)
print(count)