import Data.List

rewrite :: Int -> String -> Int
rewrite x = sum . drop x . reverse . sort . map length . group . sort . words

main = do
    cs <- getLine
    ds <- getLine
    let t = read . head . words $ cs :: Int
    let s = read . last . words $ cs :: Int
    case (t == s) of
      True  -> print 0
      False -> print $ rewrite s ds