# 1697번. 숨바꼭질
fromcollectionsimportdequeimportsysinput=sys.stdin.readlinedefbfs(v):cnt=0q=deque([[v,cnt]])whileq:v=q.popleft()vv=v[0]cnt=v[1]ifnotvisited[vv]:visited[vv]=Trueifvv==k:returncntcnt+=1ifvv*2<=100000:q.append([vv*2,cnt])ifvv+1<=100000:q.append([vv+1,cnt])ifvv-1>=0:q.append([vv-1,cnt])returncnt# n, k = 5, 17
n,k=map(int,input().split())visited=[False]*100001print(bfs(n))