WAonT5
#include <bits/stdc++.h>
using namespace std;
int k,n;
bool used[1000010];
struct node{
int n,step;
};
int main(){
cin >> k >> n;
if(n == k){
cout << 0;
return 0;
}
queue <node> q;
memset(used,0,sizeof(used));
q.push(node{k,0});
used[k] = 1;
while(!q.empty()){
node u = q.front();
q.pop();
for(int i = 1;i <= 1;i++){
node v = u;
v.step++;
v.n--;
if(used[v.n]) continue;
if(v.n == n){
cout << v.step << endl;
return 0;
}
//cout << v.n << endl;
q.push(v);
used[v.n] = 1;
}
for(int i = 1;i <= 1;i++){
node v = u;
v.step++;
v.n++;
if(used[v.n]) continue;
if(v.n == n){
cout << v.step << endl;
return 0;
}
//cout << v.n << endl;
q.push(v);
used[v.n] = 1;
}
for(int i = 1;i <= 1;i++){
node v = u;
v.step++;
v.n -= 5;
if(used[v.n]) continue;
if(v.n == n){
cout << v.step << endl;
return 0;
}
//cout << v.n << endl;
q.push(v);
used[v.n] = 1;
}
for(int i = 1;i <= 1;i++){
node v = u;
v.step++;
v.n+= 5;
if(used[v.n]) continue;
if(v.n == n){
cout << v.step << endl;
return 0;
}
//cout << v.n << endl;
q.push(v);
used[v.n] = 1;
}
for(int i = 1;i <= 1;i++){
node v = u;
v.step++;
v.n+=10;
if(used[v.n]) continue;
if(v.n == n){
cout << v.step << endl;
return 0;
}
//cout << v.n << endl;
q.push(v);
used[v.n] = 1;
}
for(int i = 1;i <= 1;i++){
node v = u;
v.step++;
v.n-=10;
if(used[v.n]) continue;
if(v.n == n){
cout << v.step << endl;
return 0;
}
//cout << v.n << endl;
q.push(v);
used[v.n] = 1;
}
}
cout << endl;
return 0;
}