import qualified Data.ByteString.Char8 as C
import Data.Maybe ( fromJust )
import Data.List

import qualified Data.Vector.Unboxed as U

cReadLn :: IO Int
cReadLn = fst . fromJust . C.readInt <$> C.getLine

getParms :: IO [Int]
getParms = map (fst . fromJust . C.readInt) . C.words <$> C.getLine

main :: IO ()
main = do
  [n,k] <- getParms
  as    <- getParms
  print $ f k as

f :: Int -> [Int] -> Int
f k as 
  | k >= l = 0 -- There are enough, no need to rewrite.
  | k <  l = g ns (l-k) 0
  where
    as' = map U.fromList . group . sort $ as
    l   = length as' -- # of kinds.
    ns  = U.fromList . sort . map U.length $ as' -- A list of # of kinds.

    g :: U.Vector Int -> Int -> Int -> Int
    g _ 0 x = x -- Assuming k<=n.
    g v k x = g (U.tail v) (k-1) (x + U.head v)