-- ALDS1_1_D Maximum Profit

import Data.Array

main = interact $ (flip (++) "\n") . show . (\(n:xs) -> greatestDiff (take n xs) (minBound :: Int)) . map read . lines

greatestDiff []  d = d
greatestDiff [x] d = d
greatestDiff (x:xs) d = greatestDiff xs (max d $ maximum [y - x | y <- xs])