import Data.List
import Control.Monad
g k (x:[])=head x 
g k (x:y:xs)=if last x+last y < k then g (k-last x) (y:xs) else head y
main=do
 [n,k]<-map read.words<$>getLine
 ab<-replicateM n (map read.words<$>getLine)
 let abl=sortBy (\x y->if fst x<=fst y then LT else GT) ab
 print$g k abl