import Data.List

main = do
  getLine
  a <- getLine >>= return . sum . map (\(x,y) -> if x<=y then y-x else y) . f . sort . map read . words :: IO Int

  print a

  where
    f [] = []
    f xs@(x:rest) = (x, len) : f (drop len xs)
      where
        r = takeWhile (==x) xs
        len = length r
