import Control.Applicative

type MinMax = (Int, Int)

updateMax :: Int -> MinMax -> MinMax
updateMax val (min, max)
  | max == 0  = (min, val)
  | max < val = (min, val)
  | otherwise = (min, max)

updateMin :: Int -> MinMax -> MinMax
updateMin val (min, max)
  | val < min = (val, max)
  | otherwise = (min, max)

cmp :: MinMax -> MinMax -> MinMax
cmp p1 p2
  | d p1 > d p2 = p1
  | d p1 < d p2 = p2
  | otherwise   = cmpMin p1 p2
    where
        d (min, max) = max - min

cmpMin :: MinMax -> MinMax -> MinMax
cmpMin p1@(f1, _) p2@(f2, _)
  | f1 < f1   = p1
  | otherwise = p2

main :: IO ()
main = do
    n  <- read <$> getLine :: IO Int
    r0 <- read <$> getLine :: IO Int
    r1 <- read <$> getLine :: IO Int
    (min, max) <- loop (n - 2) (r0, r1) (r1, 0)
    print $ max - min
    where
        loop :: Int -> MinMax -> MinMax -> IO MinMax
        loop 0 s _ = return s
        loop n s p = do
            v <- read <$> getLine :: IO Int
            let s' = updateMax v s
                p' = updateMax v p
            if s' == cmp s' p'
               then loop (n - 1) s' (updateMin v p)
               else loop (n - 1) p' (v, 0)

