module Main where

import           Control.Monad
import           Data.List
import           Data.Ord
import           Data.List.Split
import qualified Data.Vector.Unboxed as V

solve [] = 0
solve (as:ass)
  | length as < head as = length as + solve ass
  | otherwise = length as - head as + solve ass

main :: IO ()
main = do
  _ <- getLine
  ass <- group . sortOn Down . map read . words <$> getLine
  print $ solve ass
