select::Int->[Int]->[Int]
select n xs=(take n xs) ++ (drop (n+1) xs)

f::Int->[Int]->Int
f ans []=ans
f ans xs=minimum [f (g ans (xs!!e)) (select e xs)|e<-[0..((length xs)-1)]]
         where g x y=((div x 10))*10+y + if (mod x 10)>0 then 10 else 0

main = do
       xs<-getContents
       let ys=map read (lines xs)::[Int]
       print $ f 0 ys