A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())
a = A%10
if a>=5:
  a = 10-a
b = B%10
if b>=5:
  b = 10-b
c = C%10
if c>=5:
  c = 10-c
d = D%10
if d>=5:
  d = 10-d
e = E%10
if e>=5:
  e = 10-e

answer = min(A+B+b+C+c+D+d+E+e, A+a+B+C+c+D+d+E+e, A+a+B+b+C+D+d+E+e)
finalanswer = min(answer, A+a+B+b+C+c+D+E+e, A+a+B+b+C+c+D+d+E)
print(finalanswer)