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

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

solve :: Int -> Int -> [Int] -> Int
solve _ _ [] = 0
solve k c (a:as)
  | k >= c = 0
  | otherwise = a + solve k (c - a) as

main :: IO ()
main = do
  [n, k] <- map read . words <$> getLine
  as <- sort . map length . group . sort <$> readIntsLine
  print $ solve k (length as) as