import java.lang.Math

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

    var min = 0
    var max = n
    for (x in (0 until m)) {
        val (l, r) = readLine()!!.split(" ").map { it.toInt() }
        min = Math.max(l, min)
        max = Math.min(r, max)
    }

    if (max >= min) {
        println(1 + max - min)
    } else {
        println(0)
    }

}

