import Data.List
import Data.Char
main = do
  xs <- map read . lines <$> getContents :: IO [Int]
  let l = fi (tail xs) $ head xs 
  print $ ((sum $ (delete l xs)) + sumrest (map show $ delete l xs) + l)
  
fi :: [Int] -> Int -> Int
fi [] a = a
fi (x:xs) a
  |(last $ show x) == '0' = fi xs a
  |(reverse $ show x) < (reverse $ show a) = fi xs x
  |otherwise = fi xs a

sumrest :: [String] -> Int
sumrest xs = (foldl (\a x -> 10-(digitToInt $ last x)+a) 0) $ filter (\s -> (last s) /= '0') xs