import Control.Monad
import Control.Applicative

maxProfit [x] = 0
maxProfit (x:xs) = max profN profF
                   where profN = foldr(max) x xs - x
                         profF = maxProfit xs

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