import qualified Data.ByteString.Char8 as C
import qualified Data.IntMap.Strict as M
import Data.List
import Data.Maybe

main = sol <$> get >>= print

get = fmap (unfoldr (C.readInt . C.dropWhile (==' '))) . C.lines <$> C.getContents 

sol ([_,k]:ab) = fst . fromJust . find ((k<=) . snd)
  . scanl1 (\(a,b) (a',b') -> (a',b+b')) . M.toAscList
  . M.fromListWith (+) $ (\[a,b] -> (a,b)) <$> ab