from collections import deque
def min_minutes(N, K):
if N >= K:
return N - K
MAX = 200000 # 安全上界
dist = [-1] * (MAX+1)
q = deque()
dist[N] = 0
q.append(N)
while q:
x = q.popleft()
if x == K:
return dist[x]
# 三种移动
for nx in (x-1, x+1, x*2):
if 0 <= nx <= MAX and dist[nx] == -1:
dist[nx] = dist[x] + 1
q.append(nx)
# 交互示例:从标准输入读入两个整数 N K
if __name__ == "__main__":
N, K = map(int, input().split())
print(min_minutes(N, K))
def hanoi(n, src, aux, dst, moves):
"""
将 n 个盘子从 src 移到 dst,借助 aux。
盘子编号按 1..n(1 最小)。
moves 为列表,记录每一步的字符串。
"""
if n == 0:
return
# 先把上面 n-1 个盘子从 src 移到 aux
hanoi(n-1, src, dst, aux, moves)
# 再把第 n 个(即当前最大的)从 src 移到 dst
moves.append(f"移动圆盘 {n} 从柱子 {src} 到柱子 {dst}")
# 最后把 n-1 个从 aux 移到 dst
hanoi(n-1, aux, src, dst, moves)
def print_hanoi_moves(n):
moves = []
hanoi(n, 'A', 'B', 'C', moves)
for line in moves:
print(line)
if __name__ == "__main__":
# 测试:修改 n 值即可
n = int(input().strip())
print_hanoi_moves(n)