{-#LANGUAGE BangPatterns#-}
import Control.Monad
import Data.Functor

main::IO ()
main=
  do
    n <- read <$> getLine::IO Int
    list <- replicateM n (read <$> getLine)::IO [Int]
    print $ maxProfit list


maxProfit::Integral a=>[a]->a
maxProfit (x:y:ys)=maxProfit' (y:ys) x (y-x)
  where
    maxProfit'::Integral a=>[a]->a->a->a
    maxProfit' [] minV maxV = maxV
    maxProfit' (x:xs) !minV !maxV=maxProfit' xs (min x minV) (max (x-minV) maxV)