import Prelude hiding (min, max)
import qualified Data.Ord as Ord

solve :: Int -> Int -> Int -> [[Int]] -> Int
solve min max cur [] = if min >= 0 then max else 0
solve min max cur ([a, b] : xs) =
    solve (Ord.min min next) (Ord.max max next) next xs
    where next = cur + a - b

main = do
    str <- getContents
    let [n] : [m] : s' = map ((map read) . words) (lines str) :: [[Int]]
    let s = take n s'
    print $ solve m m m s

