fun max(a: Int, b: Int) = if (a > b) a else b

fun main(args: Array<String>) {
    val (n, m) = readLine()!!.split(' ').map(String::toInt)
    var mx = 1
    var mn = n
    repeat(m) {
        val (l, r) = readLine()!!.split(' ').map(String::toInt)
        if (mx < l) {
            mx = l
        }
        if (mn > r) {
            mn = r
        }
    }
    println(max(mn - mx + 1, 0))
}