fun intList() = readLine()?.split(" ")?.map(String::toInt) ?: TODO()
fun main(args: Array<String>) {
    val (n, m) = intList()
    var lMax = 0
    var rMin = Int.MAX_VALUE
    repeat(m) {
        val (l, r) = intList()
        lMax = Math.max(lMax, l)
        rMin = Math.min(rMin, r)
    }
    val result = Math.max(0, (rMin - lMax + 1))
    println(result.toString())
}
