fun main(args: Array<String>) {

    val (n, m) = readLine()!!.split(" ").map { it.toInt() }

    var lMax = 0
    var RMin = Int.MAX_VALUE

    for (i in 0 until m) {
        val (l, r) = readLine()!!.split(" ").map { it.toInt() }

        if (l > lMax) {
            lMax = l
        }

        if (r < RMin) {
            RMin = r
        }
    }

    if (RMin - lMax < 0) println(0) else println(RMin - lMax + 1)

}