import Data.List
import Control.Monad

main :: IO ()
main = do
    n <- getLine >>= return . (read :: String -> Int)
    h <- getLine >>= return . map (read :: String -> Int) . words
    putStrLn . show . snd $ foldl' (\(a,b) -> \c -> (c,if a <= c then b + c - a else b)) (0,0) h