fun main(args: Array<String>) {
    var (n, m) = readLine()!!.split(" ").map { it.toInt()}
    var min = 1
    var max = n
    for (i in 0 until m){
        var (l, r) = readLine()!!.split(" ").map { it.toInt()}
        if (min < l) min = l
        if (max > r) max = r
    }
    println(if (max - min + 1 < 0) 0 else max - min + 1)
}