import Control.Monad (replicateM)
main = do
        n <- readLn
        nums <- replicateM n readLn
        print.maxProfit $ nums
maxProfit :: [Int] -> Int
maxProfit xs = let (l',l, g) = searchMinMax xs
                   in if l == g then l - l'
                                else g - l

searchMinMax :: [Int] -> (Int,Int, Int)
searchMinMax (x:xs) = foldl func (x,x,x) xs

func (l',l,g) x
    | l > x     = (l,x,x)
    | x < g     = (l',l,g)
    | otherwise = (l',l, x)