import Data.List

  -- max: ?????????????????§???, x:?°??????????????????????list
search :: Int -> [(Int,Int)] -> [Int]
search _ [] = []
search cur_max x =
  let (ln,lv) = head x
      (hn,hv) = last x
  in
    if (hv-lv) < cur_max
    then [] -- finish
    else
      let x0 = tail x
          x1 = init x
          new_max = if ln < hn
                    then max cur_max (hv-lv)
                    else cur_max
          val     = if ln < hn
                    then [hv-lv]
                    else []
      in 
        val ++ (search new_max x0) ++ (search new_max x1)
ans x = 
    let (x0:x1:_) = x
        init_max  = x1 - x0
        s = sortBy (\(na,va) (nb,vb) -> compare va vb) $ zip [1..] x
        v = (init_max):(search init_max s)
    in
      maximum v

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