
fun main(args:Array<String>): Unit {
    val (a, b) = readLine()!!.trim().split(' ').map(String::toInt)
    val n = readLine()!!.trim().toInt()
    val array = Array(n){val (f, t) = readLine()!!.trim().split(' ').map(String::toInt)
        f until t
    }
    println(
            if (array.any{it.contains(a) || it.contains(b - 1) || (a until b).contains(it.start)}) 1 else 0
    )
}
