-- import Debug.Trace
import Data.List
import Data.Ord

getInts :: IO [Int]
getInts = map read . words <$> getLine

getData 0 xs = return xs
getData n xs = do
  (a:b:[]) <- getInts
  getData (n - 1) ((a,b):xs)

scoreA [] n = n
scoreA ((a,b):xs) n = scoreB xs (n + a)

scoreB [] n = n
scoreB ((a,b):xs) n = scoreA xs (n - b)

getScore (a,b) = a + b

main = do
  (n:ns) <- getInts
  xs <- getData n []
  print $ scoreA (sortBy (comparing (Down . getScore)) xs) 0
