import Data.Functor( (<$>))
import Data.ByteString.Lazy.Char8( readInt)
import qualified Data.ByteString.Lazy.Char8 as C8
import Data.Function( on)
import Data.Sequence(
	unstableSortBy, breakr, iterateN,
			(><),
			ViewL( (:<)), viewl,
			ViewR( (:>), EmptyR), viewr)
import qualified Data.Sequence as SQ
import Data.Foldable( toList, foldl')

main = do
    Just (n, body) <-  readInt <$> C8.getContents
    let
	indexSequence = iterateN n (+1) 0

	asc = unstableSortBy (compare `on` snd) $ SQ.zip indexSequence $
		SQ.unfoldr (readInt . C8.tail) body

	aProfit seq
	  | SQ.null seq = Nothing
	  | otherwise 
	    = let
		(ixmin,minv) :< remain = viewl seq
		(through, hit) = breakr ((ixmin<) . fst) remain
	    in
		case viewr hit		of
		rem :> (ixmax, maxv)	-> Just (maxv-minv, SQ.filter
						((ixmin>). fst) $ rem><through)
		EmptyR			-> Just (0,	    remain)

	answer = foldl' max 0  $ SQ.unfoldr aProfit asc

    print $ if answer > 0
	    then answer
	    else -- exceptional case: monotonically decreasing
		negate . minAdjacentDiff $ snd <$> toList asc
	      where
		minAdjacentDiff list@(_:xs) = minimum $ zipWith (-) xs list


