import scala.io.StdIn._
object Main extends App {
  val Array(r, s, p) = readLine.trim.split(' ').map(_.toInt)
  val times = Array.tabulate(p){_ ⇒
    val Array(i, j) = readLine.trim.split(' ').map(_.toInt)
    if (j > s) j - s + r - i + 1 else s - j + 2 + r - i
  }
  println(times.sorted.foldLeft(0){case (acc, t) ⇒ if (acc < t) t else acc + 1})
}

