import System.IO
ans' m a [] = a
ans' m a (x:xs) = 
  let m' = min m x
      a' = max a (x-m)
  in
    ans' m' a' xs

ans x = 
  let (x0:x1:xs) = x
      init_max  = x1 - x0
  in
    ans' x0 init_max (x1:xs)

main = do
  hSetBuffering stdin LineBuffering
  n <- getLine
  c <- getContents
  let i = map read $ lines c :: [Int]
      o = ans i
  print o