maxDiff :: Int -> Int -> [Int] -> Int
maxDiff minN maxN [] = maxN - minN
maxDiff minN maxN (x:xs) =
  maxDiff (min minN x) (max maxN x) xs

main = do
  _ <- getLine
  line <- getLine
  let
    xs = map read $ words line :: [Int]
    ans = maxDiff (10^10) 0 xs
  putStrLn $ show ans
