{-# LANGUAGE BangPatterns #-}

import qualified Data.List as L

import Control.Applicative
import Control.Monad       (replicateM)

main :: IO ()
main = do
    [n, k] <- getSeq
    ps     <- replicateM n getLine
    print $ solve k ps

solve :: Int -> [String] -> Int
solve k ps = inner bag id
  where
    bag = fmap L.length . L.group . L.sort $ L.head <$> ps
    inner :: [Int] -> (Int -> Int) -> Int
    inner !bag cont
        | r /= 0    = cont 0
        | otherwise = inner xs (cont . succ)
      where
        (r, xs) = L.foldr f (k, []) $ L.sort bag
        f x (k, !xs)
          | k == 0    = (     0,      x : xs)
          | x == 1    = (pred k,          xs)
          | otherwise = (pred k, pred x : xs)

getSeq  = map read . words <$> getLine
