import Data.List

f :: (Int,Int) -> Int -> (Int,Int)
f (m,a) x =
  let m' = min m x
      a' = max a (x-m)
  in
    (m',a')

ans :: [Int] -> (Int,Int)
ans x = 
  let (x0:x1:xs) = x
      init_max  = x1 - x0
  in
    foldl' f (x0,init_max) (x1:xs)

main = do
  n <- getLine
  c <- getContents
  let i = map read $ lines c :: [Int]
      (_,o) = ans i
  print o