fun main(args: Array<String>) {
    val (n, m) = readLine()!!.split(" ").map { it.toInt() }
    var ll = mutableListOf<Int>()
    var rl = mutableListOf<Int>()
    for (i in 0 until m) {
        val (l, r) = readLine()!!.split(" ").map { it.toInt() }
        ll.add(l)
        rl.add(r)
    }
    ll.sort()
    rl.sort()
    println(Math.max((rl.min()!! - ll.max()!! + 1), 0))
}
