#include <bits/stdc++.h>
using namespace std;
int main() {
freopen("KHOASO.INP","r",stdin);
freopen("KHOASO.OUT","w",stdout);
int a,b,c,d;
cin >> a >> b >> c >> d;
a = (abs(a-2) > 5) ? (10 - abs(a-2)) : abs(a-2) ;
b = (abs(b-0) > 5) ? (10 - abs(b-0)) : abs(b-0) ;
c = (abs(c-2) > 5) ? (10 - abs(c-2)) : abs(c-2) ;
d = (abs(d-5) > 5) ? (10 - abs(d-5)) : abs(d-5) ;
cout << a + b + c + d;
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+Cgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKaW50IG1haW4oKSB7CiAgICBmcmVvcGVuKCJLSE9BU08uSU5QIiwiciIsc3RkaW4pOwogICAgZnJlb3BlbigiS0hPQVNPLk9VVCIsInciLHN0ZG91dCk7CgogICAgaW50IGEsYixjLGQ7CiAgICBjaW4gPj4gYSA+PiBiID4+IGMgPj4gZDsKCiAgICBhID0gKGFicyhhLTIpID4gNSkgPyAoMTAgLSBhYnMoYS0yKSkgOiBhYnMoYS0yKSA7CiAgICBiID0gKGFicyhiLTApID4gNSkgPyAoMTAgLSBhYnMoYi0wKSkgOiBhYnMoYi0wKSA7CiAgICBjID0gKGFicyhjLTIpID4gNSkgPyAoMTAgLSBhYnMoYy0yKSkgOiBhYnMoYy0yKSA7CiAgICBkID0gKGFicyhkLTUpID4gNSkgPyAoMTAgLSBhYnMoZC01KSkgOiBhYnMoZC01KSA7CgogICAgY291dCA8PCBhICsgYiArIGMgKyBkOwoKICAgIHJldHVybiAwOwp9Cg==