import qualified Data.IntMap as M
import Data.List
 
main = do
  (_:k:as) <- map read . words <$> getContents
  print . sum . drop k . sortOn negate . M.elems $ foldr (flip (M.insertWith (+)) 1) M.empty as
 