import Control.Monad

solve :: [Int] -> Int
solve (x:y:xs) = snd $ foldl (\(a, b) c -> (min a c, max b (c - a))) (min x y, y - x) xs

main :: IO ()
main = do
    n  <- readLn
    xs <- replicateM n readLn
    print $ solve xs