module Main where

import Control.Applicative
import Control.Monad
import Data.Function

data Stat = Stat Int Int

updateStat :: Stat -> Int -> Stat
updateStat (Stat smin sdiff) x =
    Stat newMin newDiff
    where
        newMin  = min x smin
        newDiff = if newMin == smin then max (x - newMin) sdiff else sdiff

initStat :: Int -> Int -> Stat
initStat x y =
    Stat smin sdiff
    where
        smin  = min x y
        sdiff = y - x

diffStat (Stat _ sdiff) = sdiff

max_diff (x:y:xs) =
    foldl updateStat (initStat x y) xs

main = do
    times <- (read <$> getLine) :: IO Int

    xs <- ($ times) . fix $ \loop n -> do
            if n /= 0 then do
                x  <- (read <$> getLine) :: IO Int
                xs <- loop (n-1)
                pure $ x : xs
            else pure []

    print $ diffStat $ max_diff xs

