n, k = map(int, input().split())
if n >= k: print(n - k); exit(0)
dist = [float('inf')] * ((max(n, k) << 1) + 1)
dist[n] = 0
q = [n]
while q:
nq = []
for x in q:
for dx in (1, -1, x):
nx = x + dx
if nx == k: print(dist[x] + 1); exit(0)
if nx >= 0 and nx <= 2 * k and dist[nx] > dist[x] + 1:
dist[nx] = dist[x] + 1
nq.append(nx)
q = nq