Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number n.

Bob wants to get number m on the display. What minimum number of clicks he has to make in order to achieve this result?


-----Input-----

The first and the only line of the input contains two distinct integers n and m (1 ≤ n, m ≤ 10^4), separated by a space .


-----Output-----

Print a single number — the minimum number of times one needs to push the button required to get the number m out of number n.


-----Examples-----
Input
4 6

Output
2

Input
10 1

Output
9



-----Note-----

In the first example you need to push the blue button once, and then push the red button once.

In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.

Difficulty: interview

Starter code:

Solutions:
def main():
    n, m = map(int, input().split())
    res, delta = 0, 1
    while n < m:
        res += 1
        n *= 2
        delta *= 2
    while n > m:
        while n - delta >= m:
            res += 1
            n -= delta
        delta //= 2
    print(res)


def __starting_point():
    main()
__starting_point()



src, dest = [int(x) for x in str(input()).strip().split()]
num_steps = 0
if src >= dest:
    num_steps = (src - dest)
else:
    while dest > src:
        if dest % 2 == 1:
            dest += 1
        else:
            dest //= 2
        num_steps += 1
    num_steps += (src - dest)

print(num_steps)


def two_degree(n, m):
    deg = 0
    res = n
    while res<m:
        res *=2
        deg+=1
    print (res)
    return deg, res-m


my_str = input()
n, m = int(my_str.split()[0]), int(my_str.split()[1])
if m<n:
    print(n-m)
else:
    res = n
    oper = 0
    while res!=m:
        if m%2==1 and m>res:
            m += 1
            oper += 1
        elif m>res:
            m =int(m/2)
            oper += 1
        elif m<res:
            oper += (res-m)
            m = res
      #  print (m)
    print (oper)
            


import math

instr = input()
space = instr.find(' ')
inint = int(instr[:space])
outint = int(instr[space+1:])

nowhalf = outint
counts = 0
adds = 0
while True:
    if inint >= nowhalf:
        print(int(inint-nowhalf+counts+adds))
        break
    counts += 1
    pasthalf = nowhalf
    nowhalf = math.ceil(nowhalf/2)
    if nowhalf*2 > pasthalf:
        adds += 1


import math
t=input()
loc=t.split(' ')
n=int(loc[0])
m=int(loc[1])

b=math.ceil(math.log2(m/n))
c=0
temp=m
if m<=n:
    d=n-m
else:
    for i in range(1,b+1):
        if temp%2==0:
            temp=temp/2
        else:
            c=c+1
            temp=(temp+1)/2
        
    d=c+n-temp+b

print(int(d))
    


[n, m] = [int(i) for i in input().split()]
cnt = 0
while n < m:
    if m % 2:
        m += 1
        cnt += 1
    else:
        m //= 2
        cnt += 1
print(cnt + n - m)

n, m = list(map(int, input().split()))
q = [n]
b = 1
r = 0
i = 0
used = [False] * (2 * 10 ** 4 + 10)
used[n] = True
while i < len(q):
    if i == b:
        b = len(q)
        r += 1
    if q[i] == m:
        print(r)
        break
    if q[i] > 1:
        if not used[q[i] - 1]:
            q.append(q[i] - 1)
            used[q[i] - 1] = True
    if q[i] < m:
        if not used[q[i] * 2]:
            q.append(q[i] * 2)
            used[q[i] * 2] = True
    i += 1


#import sys
#sys.setrecursionlimit(20000)
f = lambda: input()
n,m = list(map(int, f().split()))

dp = [99999] * 10001
dp[n] = 0

def click():
    for i in range(0, n+1):
        dp[i] = n-i;
        if i*2 <= 10000:
            if dp[i*2] > dp[i]+1:
                dp[i*2] = dp[i]+1

    for i in range(n+1, 10001):
        if dp[i] == 99999:
            d = 1
            while(i+d <= 10000 and dp[i+d] == 99999):
                d+=1
            if i+d <= 10000:
                dp[i] = d + dp[i+d]

        if i*2 <= 10000 and dp[i*2] > dp[i]+1:
            dp[i*2] = dp[i]+1

click()

#print(dp)
print(dp[m])


n,m=map(int,input().split());a=0
while n!=m:
    a+=1;m+=1 if m<n or m&1 else-m//2
print(a)

def fun(n, m):
    if n >= m:
        return (n-m)
    Q = [n]
    mySet = set()
    cnt = 1
    while(True):
        new_Q = []
        for num in Q:
            x = 2*num
            y = num-1
            if x == m or y == m:
                return cnt
            if not x in mySet and x < 20000 and x > 0:
                mySet.add(x)
                new_Q.append(x)
            if not y in mySet and y < 20000 and y > 0:
                mySet.add(y)
                new_Q.append(y)
        Q = new_Q
        cnt += 1
        
            
n, m = [int(c) for c in input().split()]
print(fun(n, m))

3
# -*- coding: utf-8 -*-

n, m = list(map(int, input().split()))
mem = [2**30] * 4 * (max(n, m))
mem[n] = 0
q = [n]
while q:
    c = q.pop(0)
    if 2 * c < len(mem) and mem[2 * c] > mem[c] + 1:
        q.append(2 * c)
        mem[2 * c] = mem[c] + 1
    if c > 1 and mem[c - 1] > mem[c] + 1:
        q.append(c - 1)
        mem[c - 1] = mem[c] + 1
print(mem[m])


a,b=map(int,input().split())
z=0
while a<b:
    if b%2==True:
        z+=1
        b+=1
    else:
        b=b//2
        z+=1
print(str(int(abs((z+a-b)))))

n, m = map(int, input().split())
res = 0
if n >= m:
    res = n - m
else:
    while m > n:
        if m % 2 == 1:
            m += 1
        else:
            m //= 2
        res += 1
    res += (n - m)
print(res)

m, n = [int(i) for i in input().split()]

def d(begin, end):
   #print(begin, end)
    if begin == end:
       return 0

    if begin == end + 1:
        return 1

    if end % 2 == 0 and end // 2 == begin:
        return 1

    if begin > end:
        return begin - end

    if end % 2 == 0:
        return d(begin, end // 2) + 1

    return d(begin, end + 1) + 1

print(d(m, n))























from math import ceil
n, m = list(map(int, input().split()))
step = 0
if n >= m:
	step += n-m
else:
	k = m
	while n < k:
		k = k / 2
	while n != m:
		if n - 1>= k:
			n -= 1
			step += 1
		else:
			k = 2*k
			n = 2*n
			step += 1
print(step)


def main() -> object:
    """

    :rtype : Integer
    :return: The answer which the problem is required.
    """
    n, m = [int(i) for i in input().split()]
    count = 0
    while n < m:
        if m % 2 == 0:
            m >>= 1
        else:
            m += 1
        count += 1
    count += n - m
    return count

def __starting_point():
    print(main())
__starting_point()

"""
def main():
    n, m = map(int, input().split())
    max = 10 ** 4
    gr = []
    for i in range(max):
        gr.append([0] * max)
    i, j, k, l = 0,0,m,n
    while gr[i][j] != 1
    
def main():
    n, m = map(int, input().split())
    l = 0
    while n != m:
        if n >= m:
            l += n-m
            n = m
        else:
            if m % 2:
                l += 1
                m += 1
            else:
                if m // 2 <= n:
                    l += 1 + n - m //2
                    n = m
                else:
                    n *= 2
                    l += 1
    print(l)
"""
def main():
    n, m = list(map(int, input().split()))
    print(rec(n,m))
def rec(n,m):
    if m <= n:
        return n-m
    else:
        if m % 2:
            return rec(n,m+1)+1
        else:
            return rec(n, m // 2) + 1
def __starting_point():
    main()

__starting_point()

def main():
    n, m = list(map(int, input().split()))
    print(rec(n,m))
def rec(n,m):
    if m <= n:
        return n-m
    else:
        if m % 2:
            return rec(n,m+1)+1
        else:
            return rec(n, m // 2) + 1
def __starting_point():
    main()

__starting_point()

n,m = list(map(int,input().split()));
a = 0
while n != m:
    a+=1;m+=1 if m<n or m&1 else-m//2
print(a)


def buttons(m,n, Steps) :
    if m == n :
        return Steps
    elif m%2 == 0 and m > n :
        return buttons(m//2 , n, Steps + 1)
    elif m%2 == 1 and  m > n :
        return buttons((m+1)//2, n, Steps + 2)
    else :
        return Steps + (n - m)

[n,m] = (input()).split(' ')
print(buttons(int(m),int(n),0))





inpt = input().split()
n = int(inpt[0])
m= int(inpt[1])
moves =0
while(m != n):
    if(m%2==1 or m <n):
        m +=1
        moves +=1
    else:
        m=m/2
        moves +=1
print(moves)
        


import sys
numbers=sys.stdin.readline().split(" ")
numbers = list(map(int, numbers))
p=numbers[0]
q=numbers[1]

count2=0
count1=0

while(q>p):
    
    if(q%2!=0):
        q=(q+1)/2
        count2=count2+1
        count1=count1+1

    elif(q%2==0):
        q=q/2
        count2=count2+1

diff=p-q
ans=count2+count1+diff
print(int(ans))
    



# red, blue, display
# init - display N
# red: N*2
# blue N-1

import sys
#sys.setrecursionlimit(10000)
from functools import lru_cache
n, m = [int(x) for x in input().split()]

# Other direction:
# m++ or m/2, reach n


res = 0
while n < m:
    res += 1
    if m % 2 == 0:
        m //= 2
    else: m += 1

res += (n-m)

print(res)