import java.util.*

fun main(args: Array<String>) {
    val (W, H, N) = readLine()!!.split(" ").map{it.toInt()}
    val st = Array(H + 2) { TreeSet<Int>() }

    for (i in 1..N) {
        val (x, y) = readLine()!!.split(" ").map{it.toInt()}
        st[y].add(x)
    }

    for (i in 1 .. H + 1) {
        st[i].add(W + 1)
    }

    var x = 1
    var y = 1
    var res = W
    while(x <= W) {
        res = Math.min(res, (st[y].higher(x) ?: res + 1) - 1)
        x++
        if (y < H && !st[y + 1].contains(x)) {
            y++
        }
    }

    println(res)
}