import           Data.List


main :: IO ()
main = do
    [n ,k] <- getInts
    as <- sortBy (\a b -> compare (length a)  $ length b)
          . group . sort <$> getInts
    print $ solve as k

getInts :: IO [Int]
getInts = map read . words <$> getLine

solve xs k = go xs
    where
      go (y:ys)
          | length ys < k = 0
          | otherwise = length y + go ys
