import Data.List
import Control.Monad

main =  readLn >>= flip replicateM readLn >>= print . solve

solve :: [Int] -> Int
solve = maximumBy cmpf . calc
    where
        cmpf lhs rhs = compare x y
            where
                x
                    | lhs `mod` 10 == 0 = 0
                    | otherwise = lhs
                y
                    | rhs `mod` 10 == 0 = 0
                    | otherwise = rhs

calc :: [Int] -> [Int]
calc (x : xs) = calc xs >>= (\y -> [x + y, y])
calc _ = [0]
