from collections import defaultdict
x, y = map(int, input().split())
memo = defaultdict(lambda : -1)


def score(n):
    if memo[n] != -1:
        return memo[n]
    if n <= x:
        memo[n] = x - n
    elif n % 2 == 0:
        memo[n] = min(score(n // 2) + 1, n - x)
    else:
        memo[n] = min(score(n + 1) + 1, score(n - 1) + 1)
    return memo[n]


print(score(y))

c73183f12ad8164cb0128f3ec0fe771ebac88e4a
<mask token>


def score(n):
    if memo[n] != -1:
        return memo[n]
    if n <= x:
        memo[n] = x - n
    elif n % 2 == 0:
        memo[n] = min(score(n // 2) + 1, n - x)
    else:
        memo[n] = min(score(n + 1) + 1, score(n - 1) + 1)
    return memo[n]


<mask token>

<mask token>


def score(n):
    if memo[n] != -1:
        return memo[n]
    if n <= x:
        memo[n] = x - n
    elif n % 2 == 0:
        memo[n] = min(score(n // 2) + 1, n - x)
    else:
        memo[n] = min(score(n + 1) + 1, score(n - 1) + 1)
    return memo[n]


print(score(y))

<mask token>
x, y = map(int, input().split())
memo = defaultdict(lambda : -1)


def score(n):
    if memo[n] != -1:
        return memo[n]
    if n <= x:
        memo[n] = x - n
    elif n % 2 == 0:
        memo[n] = min(score(n // 2) + 1, n - x)
    else:
        memo[n] = min(score(n + 1) + 1, score(n - 1) + 1)
    return memo[n]


print(score(y))

from collections import defaultdict
x, y = map(int, input().split())
memo = defaultdict(lambda : -1)


def score(n):
    if memo[n] != -1:
        return memo[n]
    if n <= x:
        memo[n] = x - n
    elif n % 2 == 0:
        memo[n] = min(score(n // 2) + 1, n - x)
    else:
        memo[n] = min(score(n + 1) + 1, score(n - 1) + 1)
    return memo[n]


print(score(y))
