import Data.List
getInts :: IO [Int]
getInts = map read . words <$> getLine
main :: IO ()
main = do
  [n,k] <- getInts
  as <- sort . map (\x -> (length x , head x)) . group . sort <$> getInts
  let nSyurui = length as
  print $ if nSyurui <= k
          then 0
          else sum . map fst $ take (nSyurui - k) as
  return ()
