fun main(args: Array<String>) {
    val (N, M) = listOfInt()
    var maxL = 0
    var minR= N
    for (m in 0 until M) {
        val (l, r) = listOfInt()
        if (maxL < l) maxL = l
        if (minR > r) minR = r
    }
    val ans = Math.max(0, minR - maxL + 1)
    println(ans)
}
fun next() = readLine()!!
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map(String::toInt)