import java.util.*

fun main(args: Array<String>) {
    val (N, M) = readLine()!!.split(" ").map {it.toInt()}
    val ps = Array(M) { readLine()!!.split(" ").map {it.toInt()}}

    println(Math.max(Collections.min(ps.map { it[1] }) - Collections.max(ps.map {it[0]}) + 1, 0))
}
