#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<int> p(5);
  for (auto& x : p) {
    cin >> x;
  }
  vector<int> flg(5, 0);
  vector<int> rest(5, 10);
  auto time = 0;
  while (accumulate(flg.begin(), flg.end(), 0) != 5) {
    for (auto& x : rest) {
      x = 10;
    }
    for (auto i = 0; i < 5; ++i) {
      if (flg[i] == 1) continue;
      rest[i] = (time + p[i]) % 10;
    }
    auto miniter = min_element(rest.begin(), rest.end());
    auto idx = std::distance(rest.begin(), miniter);
    flg[idx] = 1;
    time += p[idx] + *miniter;
    cout << "flg:" << accumulate(flg.begin(), flg.end(), 0) << " time:" << time
         << endl;
  }
  cout << time;
  return 0;
}
