import Control.Monad
import Control.Applicative

maxProfit [x] _ = -1000000000
maxProfit (x:xs) lowest = 
    if x > lowest then maxProfit xs lowest
    else max (foldr(max) 0 xs - x) (maxProfit xs x)
main = do
    s <- (drop 1.map read.lines) <$> getContents ::IO[Int]
    putStrLn $ show $ maxProfit s (s!!0)