object Main extends App {
	val n = scala.io.StdIn.readInt
	val a = new Array[Long](n)
	var bs = Long.MaxValue

	for(i<-0 until n){
		val tp = scala.io.StdIn.readLine.split(" ").map(_.toLong)
		a(i) = tp(0)
		
		if(tp(0) > tp(1)){
			bs = math.min(bs, tp(1))
		}
	}

	if(bs == Long.MaxValue){
		println(0)
	}else{
		println(a.sum - bs)
	}
}