I = ["{0:03d}".format(int(n)) for n in open(0).read().split()]
c = 0
min_z = 9
for i in I:
    x, y, z = map(int, i)
    if 0 < z < min_z:
        min_z = z
    if 0 < z:
        y +=1
    if 9 < y:
        x += 1
        y -= 10
    n = x * 100 + y * 10
    c += n
print(c+min_z-10)