import qualified Data.ByteString.Char8 as BC
import Data.Maybe
import Data.List

readIntsLine :: IO [Int]
readIntsLine = map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine

solve :: [(Int, Int)] -> Int
solve [] = 0
solve ((num, len):as)
  | num < len = len - num + solve as
  | num > len = len + solve as
  | otherwise = solve as

main :: IO ()
main = do
  getLine
  as <- map (\x -> (head x, length x)) . group . sort <$> readIntsLine
  print $ solve as