
object Main extends App{
  import scala.io.StdIn._
  import scala.math._
  val n = readLine().trim().toInt
  var sum = 0
  var minB = 1000000001
  for (_ <- 0 until n){
    val (a::b::_) = readLine().trim().split(' ').map(_.toInt).toList
    sum += a
    if (a > b){
      if (minB > b){
        minB = b
      }
    }
  }
  if (minB == 1000000001){
    println(0)
  }else{
    println(sum - minB)
  }
}