import Data.List

main = do
  n <- readLn
  xss <- mapM (const $ fmap (map read . words) getLine) [1..n]
  print (solve xss)

solve :: [[Int]] -> Int
solve xss =
  if as==bs then 0 else sum bs - foldr f (10^9) xss
  where
    [as,bs] = transpose xss
    f [a,b] c | a > b     = min c b
              | otherwise = c