fun main(array: Array<String>) {
    val (n, m) = readLine()!!.split(" ").map { it.toInt() }
    var arr = Array(n){0}
    var ans = 0
    var llist = mutableListOf<Int>()
    var rlist = mutableListOf<Int>()
    repeat(m) {
        val (l, r) = readLine()!!.split(" ").map { it.toInt()}
        llist.add(l)
        rlist.add(r)
    }
    val max = llist.max()
    val min = rlist.min()
    if(max!! <= min!!) print(min - max!! + 1)
    else print(0)
}