import java.util.*
import java.math.*
fun main(args: Array<String>) {

    var (N, M) = readLine()!!.split(" ").map { it.toInt() }
//    var N = readLine()!!.toInt()
//    val D = readLine()!!.split(" ").map { it.toLong() }
//    val A = readLine()!!.split(" ").map { it.toInt() }.toIntArray()

    val mod = 1000000007L

    val L = mutableListOf<Int>()
    val R = mutableListOf<Int>()
    for (n in 1..M) {
        var (l, r) = readLine()!!.split(" ").map { it.toInt() }
        L.add(l)
        R.add(r)
    }
    var ans = R.min()!! - L.max()!! + 1
    if (ans < 0) ans = 0
    println(ans)
//    println("%.9f".format(ans))
}
