-- ALDS1_1_D Maximum Profit

import Data.Array

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

solve' (n:xs) = solve $ listArray (0,n-1) xs
    where solve xs = let (l,h) = bounds xs in maximum [xs!j - xs!k | j <- [l..h], k <- [l..h], j > k]