{-# OPTIONS_GHC -O #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ViewPatterns #-}

import Control.Monad
import Data.Function
import Data.List
import qualified Data.ByteString.Char8 as B
import qualified Data.IntMap as M

main = do
    [n,k] <- map read.words<$>getLine :: IO [Int]
    as <- sortOn snd.M.toList.
        -- 数値のリスト -> 数値をkeyとして出現回数のMAPに
        foldl' (\m k -> M.insertWith(+)k 1 m) M.empty.
        unfoldr (B.readInt.B.dropWhile(==' ')) <$> B.getLine :: IO [(Int,Int)]
    let a = (fix $ \loop c k n ((_,e):xs) -> if k >= n then c else loop (c+e) k (n-1) xs)  0 k (length as) as 
    print a
