import Data.List

main::IO()
main = do
    n <- readLn::IO Int
    xs <-map read . words <$> getLine::IO [Integer] 
    print $ (query . group . sort) xs


query::[[Integer]] -> Integer
query[] = 0
query (x:xs) = if x!!0 == fromIntegral(length x) then (0 + query xs) else (addOrSub x + query xs)  

addOrSub::[Integer] -> Integer
addOrSub x = case fromIntegral(length x) <= x!!0 of
                  -- eg.7 7 7 7 7
                 True -> fromIntegral (length x)
                 False -> fromIntegral(length x) - (x!!0)
