fun main(args: Array<String>) = println(run {
    val (n, m) = readLine()!!.split(" ").map { it.toInt() }
    val lr = (1..m).map { readLine()!!.split(" ").map { it.toInt() } }

    val imos = IntArray(n+2)
    lr.forEach {
        val (l, r) = it
        imos[l]++
        imos[r+1]--
    }
    imos.accumulated().count { it == m }
})

fun IntArray.accumulated(): List<Int> { var sum = 0; return this.map { sum += it; sum } }
