#include <bits/stdc++.h>
using namespace std;
int main() {
  int input[5];
  cin >> input[0];
  cin >> input[1];
  cin >> input[2];
  cin >> input[3];
  cin >> input[4];
  int time = 0;
  const int N = 5;
  vector<int> v(N);
  iota(v.begin(), v.end(), 0);
  int min = 99999;
  do {
    time = 0;
    int count = 0;
    for (auto x : v) {
      time += input[x];
      int addnum = 5 - time % 5;
      if (addnum == 5) addnum = 0;
      if (count != 4) time += addnum;
      count++;
    }
    min = std::min(min, time);
  } while (next_permutation(v.begin(), v.end()));
  cout << min << endl;
  return 0;
}
