import Data.List

solve :: [Int] -> Int
solve (n:xs) = maximum $ map (\i -> (maximum $ drop (i + 1) xs) - (xs !! i)) [0 .. n - 2]

main :: IO ()
main = getContents >>= print . solve . map read . lines