import Control.Monad (replicateM)
main = do
        n <- readLn
        nums <- replicateM n readLn
        print.maxProfit $ nums
maxProfit :: [Int] -> Int
maxProfit = maximum.mp
mp [] = []
mp (x:xs) = searchMax (x:xs) : mp xs

searchMax [x]    = minBound
searchMax (x:xs) = maximum xs - x