import sys
sys.stdin = open("input.txt", "rt")
from collections import deque
MAX = 100000
dis = [0] * (MAX+1)
ch = [0] * (MAX+1)
n,m = map(int,input().split())
dQ = deque()
dQ.append(n)
while dQ:
now = dQ.popleft()
if now == m :
break
for next in(now -1, now +1, now +5):
if 0< next < MAX :
if ch[next] == 0:
dQ.append(next)
ch[next]=1
dis[next] = dis[now]+1
print(dis[m])