import Control.Monad
import Control.Applicative

main :: IO ()
main = do
    n <- read <$> getLine
    rs <- map read <$> replicateM n getLine
    print $ solve rs

solve :: [Int] -> Int
solve (x1:x2:xs) = solve' x2 x1 xs
    where
        solve' :: Int -> Int -> [Int] -> Int
        solve' mx mn [] = mx - mn
        solve' mx mn [n] = (if mx > n then mx else n) - mn
        solve' mx mn (n:n2:ns) = solve' mx' mn' (n2:ns)
            where
                upd = mn > n
                mn' = if upd
                          then n
                          else mn
                mx' = if upd
                          then n2
                          else if mx > n
                                 then mx
                                 else n