import           Control.Applicative
import           Control.Monad
import           Data.List
import           Text.Printf

minAfter::(Ord a)=>[a]->[a]
minAfter []     = []
minAfter [x]    = []
minAfter [x,y]  = [y]
minAfter (x:xs) = min (head xs) (head $ minAfter xs) : minAfter xs

minBefore::(Ord a)=>[a]->[a]
minBefore = reverse . minAfter . reverse

main = do
    n<- getLine
    a<- map (read::String->Int) <$> replicateM (read n) getLine
    print $ maximum $ zipWith (-) (tail a) (minBefore a)
