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

main=do
    (n:k:_)<-map read.words<$>getLine::IO[Int]
    abs<-replicateM n $ unfoldr (B.readInt.B.dropWhile(==' '))<$>B.getLine::IO[[Int]]
    print . src k . M.toAscList.foldl' (\m (a:b:_)->M.insertWith(+)a b m) M.empty $ abs
--
src k ((i,n):r)
    | k<=n = i
    | True = src (k-n) r