import Control.Applicative ((<$>), (<*>))
import Control.Monad
import Data.List

main :: IO ()
main = do
  [n, k] <- getl $ wrds toInt
  solve k <$> replicateM n getLine >>= print

solve :: Int -> [String] -> Int
solve k xs = f 0 ys
  where
    ys = map length . group . map head $ xs
    f c zs
      | length zs < k = c
      | otherwise = f (c+1) ((filter (/= 0) . map (subtract 1) $ take k szs) ++ drop k szs)
      where
        szs = sortBy (flip compare) zs

toInt :: String -> Int
toInt = read

wrds :: (String -> a) -> String -> [a]
wrds f = map f . words

getl :: (String -> a) -> IO a
getl f = f <$> getLine
