import Data.List

max' Nothing  Nothing = Nothing
max' (Just a) Nothing = Just a
max' Nothing  (Just b)= Just b
max' (Just a) (Just b)= Just (max a b)

search (h:hs) (t:ts) =
  if h == t
  then Nothing
  else
    let (hn,hv) = h
        (tn,tv) = t
    in
      if hn < tn
      then Just (tv - hv)
      else max' (search (h:hs) ts) (search hs (t:ts))

shrinkLeft _ [] = []
shrinkLeft (n0,v0) ((n1,v1):ns) =
  if n0 < n1
  then shrinkLeft (n0,v0) ns
  else ((n1,v1):shrinkLeft (n0,v0) ns)

searchLeft (x0:[]) = Nothing
searchLeft (x0:xs) =
  let (n0,v0) = x0
      (nl,vl) = last xs
  in
    if n0 < nl
    then Just (vl - v0)
    else
      let sh = shrinkLeft x0 xs
      in
        searchLeft sh
      

ans x = 
    let z = zip [1..] x
        s = sortBy (\(na,va) (nb,vb) -> compare va vb) z
        vl = searchLeft s
    in
      case vl of
        Just v' -> v'
        Nothing -> ans2 x

ans2 (x0:x1:[]) = x1 - x0
ans2 (x:xs) = 
    let min = x
        max = maximum xs
        p0  = max - min
        p1  = ans2 xs
    in
        maximum [p0,p1]

main = do
    n <- getLine
    c <- getContents
    let i = map read $ lines c :: [Int]
        o = ans i
        z = zip [1..] i
        s = sortBy (\(na,va) (nb,vb) -> compare va vb) z
    print o