-- Getting Started - Maximum Profit

import Control.Applicative
import Control.Monad
import Data.List

main :: IO ()
main = do
  n <- readLn
  xs <- map read <$> replicateM n getLine
  print $ maximumProfit xs

maximumProfit :: [Int] -> Int
maximumProfit xs = maximum $ zipWith (-) (tail xs) (findMin xs)

findMin :: [Int] -> [Int]
findMin (x : xs) = x : loop x xs
  where
    loop _ [] = []
    loop m (x : xs)
      | m < x     = m : loop m xs
      | otherwise = x : loop x xs

