main :: IO ()
main = do
  getLine
  as <- map read . words <$> getLine
  print $ solve as

solve :: [Int] -> Int
solve as = uncurry (-) $ foldr f (0, maxBound) as
  where
    f x (a, b) = (x `max` a, x `min` b)
