import Control.Arrow
import Control.Monad
import Data.List
import qualified Data.ByteString.Char8 as B
import Data.Ord

main :: IO ()
main = replicateM 5 readLn >>= print . solve

solve :: [Int] -> Int
solve = sum . edit . sortBy cmpf
    where
        cmpf lhs rhs = compare l r
            where
                l 
                    | lm > 0 = lm
                    | otherwise = 9
                r 
                    | rm > 0 = rm
                    | otherwise = 9
                lm = lhs `mod` 10
                rm = rhs `mod` 10
        edit (x : xs) = x : map mf xs
        mf x
            | m > 0 = x - m + 10
            | otherwise = x
            where
                m = x `mod` 10

readLine :: IO [Int]
readLine = unfoldr (fmap (second (maybe B.empty snd . B.uncons)) . B.readInt) <$> B.getLine

readContents :: Int -> IO [[Int]]
readContents = flip replicateM readLine