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 . sort . map head $ xs
    f c zs
      | length zs < k = c
      | otherwise = f (c + sn) ((filter (/= 0) . map (subtract sn) $ szs1) ++ szs2)
      where
        szs = sortBy (flip compare) zs
        szs1 = take k szs
        szs2 = drop k szs
        sn = if null szs2 then last szs1 else (last szs1) - (head szs2) + 1

toInt :: String -> Int
toInt = read

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

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