import Control.Arrow
import Control.Monad
import Data.List
import qualified Data.ByteString.Char8 as B
import Data.Ord

main :: IO ()
main = readLine >>= main'
    where
        main' [n, k] = readContents n >>= print . solve k 

solve :: Int -> [[Int]] -> Int
solve k = check k . sortBy cmpf
    where
        cmpf = comparing head
        check c ([a, b] : xs)
            | c > b = check (c - b) xs
            | otherwise = a

readLine :: IO [Int]
readLine = unfoldr (\s -> second (maybe B.empty snd . B.uncons) <$> B.readInt s) <$> B.getLine

readContents :: Int -> IO [[Int]]
readContents = flip replicateM readLine