module Main (main) where
import Control.Monad.State

strToInt str = (read str :: Integer)

readLineN n = do
  str <- getLine
  if (n > 1)
    then do
      tail <- readLineN (n-1)
      return $ (strToInt str) : tail
    else
      return $ (strToInt str) : []

calcProfit :: (Ord a, Num a) => State ([a], a, a) a
calcProfit = do
  (xs, maxProf, min) <- get
  case xs of
    [] -> return maxProf
    head:tail -> do
      if head < min then put (tail, maxProf, head)
      else if (head - min) > maxProf then put (tail, head - min, min)
      else put (tail, maxProf, min)
      calcProfit

main = do
  str <- getLine
  ls <- readLineN $ strToInt str
  -- putStrLn $ show ls
  let head1:head2:tail = ls
  putStrLn $ show $ evalState calcProfit (tail, head2 - head1, min head1 head2)
