import qualified Data.IntMap as M
import Data.List
 
main = do
  [n, k] <- map read . words <$> getLine
  as <- map read . words <$> getLine
  let dict = mkDict as
  print $ solve k dict
 
mkDict :: [Int] -> M.IntMap Int
mkDict [] = M.empty
mkDict (x:xs) = M.insertWith (+) x 1 $ mkDict xs
 
solve :: Int -> M.IntMap Int -> Int
solve k dict
  | M.size dict <= k = 0
  | otherwise = n + solve k d
  where (d, n) = takeMin dict 
 
takeMin :: M.IntMap Int -> (M.IntMap Int, Int)
takeMin dict = (M.fromList xs, snd x)
  where (x:xs) = sortOn snd . M.toList