object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val N = sc.nextInt
  val scores = (0 until N)
    .map { _ => (sc.nextLong, sc.nextLong) }
    .toArray
    .sortWith { _._1 < _._1 }
  val (_, acc) = scores.foldLeft { (0L, 0L) } {
    case ((rAcc, cnt), (r, s)) => (r, cnt + r - rAcc)
  }
  println(scores.last._2 + acc)
}
