import Data.Function (on)
import Data.List (group, sort, sortBy)

main :: IO ()
main = do
    (_:k:as) <- getParams
    print $ solve k as

getParams :: IO [Int]
getParams = map read . words <$> getContents

solve :: Int -> [Int] -> Int
solve k = length . rewrites k

rewrites :: Int -> [Int] -> [Int]
rewrites k = concat . drop k . sortBy lenDesc . group . sort
  where
    lenDesc = flip compare `on` length
