fun main(args: Array<String>) {
    val (n ,m) = readLine()!!.split(' ').map { it.toInt() }
    val (l1, r1) = readLine()!!.split(' ').map { it.toInt() }
    val ans = (1 until m).fold(Pair(l1, r1)) { acc, i ->
        val (l, r) = readLine()!!.split(' ').map { it.toInt() }
        Pair(Math.max(acc.first, l), Math.min(acc.second, r))
    }
    println(Math.max(ans.second - ans.first + 1, 0))
}