import Data.List
main :: IO()
main = do
  _ <- getLine
  a <- map read . words <$> getLine
  print $ slv a []

slv :: [Integer] -> [Integer] -> Integer
slv s _ | low == 0 = 0
        | otherwise = up - low + 1
  where low = lower (sort s) (map (+1) (sort s))
        up = upper revlist revlist
        revlist = reverse $ sort s

lower :: [Integer] -> [Integer] -> Integer 
lower s (p:ps) | length arc == length abc = p
               | otherwise = lower s ps
  where (arc, abc) = span (<p) s
lower _ [] = 0

upper :: [Integer] -> [Integer] -> Integer 
upper s (p:ps) | length arc == length abc = p
               | otherwise = upper s ps
  where (arc, abc) = span (>=p) s
upper _ [] = 0
