fun main(args: Array<String>) {
    val (a, b) = readLine()!!.split(" ").map { it.toInt() }
    val n = readLine()!!.toInt()
    val arr = IntArray(1010) {
        0
    }
    arr[a]++
    arr[b]--
    repeat(n) {
        val (s, f) = readLine()!!.split(" ").map { it.toInt() }
        arr[s]++
        arr[f]--
    }
    for(i in 1..1006) {
        arr[i] += arr[i-1]
    }
    println(if(arr.all { it < 2 }) 0 else 1)
}
