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
      val     = hv - lv
  in
    if val < cur_max
    then [] -- finish
    else
      let new_max = if ln < hn
                    then max cur_max val
                    else cur_max
          x0 = tail x
          x1 = init x
          r0 = search new_max x0
          r1 = search new_max x1
          rr = r0 ++ r1
      in 
        if ln < hn
        then val:rr
        else rr
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