from collections import deque
import sys
input = sys.stdin.readline


def bfs(n):
    count = 0
    queue = deque([(n, count)])
    while queue:
        val, cnt = queue.popleft()
        count = cnt
        if not visited[val]:
            visited[val] = 1
            if val == k:
                return count
            count += 1
            if val - 1 >= 0:
                queue.append((val - 1, count))
            if val + 1 <= 100000:
                queue.append((val + 1, count))
            if val * 2 <= 100000:
                queue.append((val * 2, count))
    return count


n, k = map(int, input().split())
visited = [0] * 100001
print(bfs(n))

2354517435f8fed87392f8bc72bb10a5a5109d52
<mask token>


def bfs(n):
    count = 0
    queue = deque([(n, count)])
    while queue:
        val, cnt = queue.popleft()
        count = cnt
        if not visited[val]:
            visited[val] = 1
            if val == k:
                return count
            count += 1
            if val - 1 >= 0:
                queue.append((val - 1, count))
            if val + 1 <= 100000:
                queue.append((val + 1, count))
            if val * 2 <= 100000:
                queue.append((val * 2, count))
    return count


<mask token>

<mask token>


def bfs(n):
    count = 0
    queue = deque([(n, count)])
    while queue:
        val, cnt = queue.popleft()
        count = cnt
        if not visited[val]:
            visited[val] = 1
            if val == k:
                return count
            count += 1
            if val - 1 >= 0:
                queue.append((val - 1, count))
            if val + 1 <= 100000:
                queue.append((val + 1, count))
            if val * 2 <= 100000:
                queue.append((val * 2, count))
    return count


<mask token>
print(bfs(n))

<mask token>
input = sys.stdin.readline


def bfs(n):
    count = 0
    queue = deque([(n, count)])
    while queue:
        val, cnt = queue.popleft()
        count = cnt
        if not visited[val]:
            visited[val] = 1
            if val == k:
                return count
            count += 1
            if val - 1 >= 0:
                queue.append((val - 1, count))
            if val + 1 <= 100000:
                queue.append((val + 1, count))
            if val * 2 <= 100000:
                queue.append((val * 2, count))
    return count


n, k = map(int, input().split())
visited = [0] * 100001
print(bfs(n))

from collections import deque
import sys
input = sys.stdin.readline


def bfs(n):
    count = 0
    queue = deque([(n, count)])
    while queue:
        val, cnt = queue.popleft()
        count = cnt
        if not visited[val]:
            visited[val] = 1
            if val == k:
                return count
            count += 1
            if val - 1 >= 0:
                queue.append((val - 1, count))
            if val + 1 <= 100000:
                queue.append((val + 1, count))
            if val * 2 <= 100000:
                queue.append((val * 2, count))
    return count


n, k = map(int, input().split())
visited = [0] * 100001
print(bfs(n))
