import Control.Monad

main = do
  n<-readLn
  ab<-replicateM n$(\[a,b]->(a,b)).map read.words<$>getLine
  print$solve ab

solve ab
  | null bs = 0
  | otherwise = sum(map fst ab) - minimum bs
  where bs=map snd $ filter (uncurry(>)) ab