import Control.Monad
import Control.Applicative

maxProfit [x] m = x - m
maxProfit (x:xs) m
    | x < m     = max (x-m) (maxProfit xs x)
    | otherwise = max (x-m) (maxProfit xs m)

main = do
    s <- (drop 1.map read.lines) <$> getContents ::IO[Int]
    putStrLn $ show $ maxProfit (drop 1 s) (s!!0)