A = str(input())
B = str(input())
C = str(input())
D = str(input())
E = str(input())
a = int(A[-1:])
b = int(B[-1:])
c = int(C[-1:])
d = int(D[-1:])
e = int(E[-1:])
F = [a,b,c,d,e]
G = F.count(0)
H = (10-a)+(10-b)+(10-c)+(10-d)+(10-e)
a = 9 if a == 0 else a
b = 9 if b == 0 else b
c = 9 if c == 0 else c
d = 9 if d == 0 else d
e = 9 if e == 0 else e
I = min([a,b,c,d,e])
J = int(A) +int(B) +int(C) + int(D) + int(E) -10*G + I -10
print(H+J)