a = int(input())
a1 = a%5
a2 = a + (5-a1)%5
b = int(input())
b1=b%5
b2 = b + (5-b1)%5
c = int(input())
c1=c%5
c2 = c + (5-c1)%5
d = int(input())
d1=d%5
d2 = d + (5-d1)%5
e = int(input())
e1=e%5
e2 = e + (5-e1)%5
if min(a1,b1,c1,d1,e1) == 0:
    ans = a2+b2+c2+d2+e2
else:
    ans = a2+b2+c2+d2+e2 -5 +min(a1,b1,c1,d1,e1)
print(ans)