fun main(args: Array<String>) {
    val (n, m) = readLine()!!.split(" ").map { it.toInt() }
    val lrList = (1..m).map { readLine()!!.split(" ").map { it.toInt() } }
        .map { Pair(it[0], it[1]) }

    val leftMax = lrList.maxBy { pair -> pair.first }?.first!!
    val rightMin = lrList.minBy { pair -> pair.second }?.second!!
    val answer = Math.max(rightMin - leftMax + 1, 0)
    println(answer)
}
