import Control.Applicative
import Control.Monad
import Data.List

digits :: Integer -> [Integer]
digits x = map (\i -> x`div`(10^i)`mod`10) [0..12]

main :: IO ()
main = do
  getLine
  xs <- map read . words <$> getLine
  print $ sum $ map maximum $ transpose $ map (digits . sum) $ subsequences xs