import Control.Monad( replicateM)
import Data.Function( on)
import Data.List( groupBy, sort)
main = do
    [n,k] <- return . map read . words =<< getLine
    ps <- replicateM n getLine
    let sorted = sort ps
	gs = groupBy ((==) `on` head) sorted
	datalist = map length gs
	process n list
	  | length list < k	= n
	  | otherwise	=
		let (kps, rem) = splitAt k list
		    l = filter (0/=) $ map pred kps
		in process (n+1) (l++rem)
    print $ process 0 datalist