#include<iostream>
#include<algorithm>
using namespace std;
const int khoa[4] = {2, 0, 2, 5};
int a[0];
main(){
for (int i = 0; i < 4; i++) {
cin >> a[i];
}
int dem = 0;
for (int i = 0; i < 4; i++) {
int an = a[i] - khoa[i];
if (an < 0) an = an*(-1);
dem = dem + min(an, khoa[i] - a[i] +10);
}
cout << dem << endl;
}
I2luY2x1ZGU8aW9zdHJlYW0+CiNpbmNsdWRlPGFsZ29yaXRobT4KCnVzaW5nIG5hbWVzcGFjZSBzdGQ7Cgpjb25zdCBpbnQga2hvYVs0XSA9IHsyLCAwLCAyLCA1fTsKaW50IGFbMF07CgptYWluKCl7Cglmb3IgKGludCBpID0gMDsgaSA8IDQ7IGkrKykgewoJCWNpbiA+PiBhW2ldOwoJfQoJaW50IGRlbSA9IDA7Cglmb3IgKGludCBpID0gMDsgaSA8IDQ7IGkrKykgewoJCWludCBhbiA9IGFbaV0gLSBraG9hW2ldOwoJCWlmIChhbiA8IDApIGFuID0gYW4qKC0xKTsKCQlkZW0gPSBkZW0gKyBtaW4oYW4sIGtob2FbaV0gLSBhW2ldICsxMCk7Cgl9CgkKCWNvdXQgPDwgZGVtIDw8IGVuZGw7Cn0K