import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val m = sc.nextInt()
    var maxL = 0
    var minR = Int.MAX_VALUE
    repeat(m) {
        maxL = Math.max(maxL, sc.nextInt())
        minR = Math.min(minR, sc.nextInt())
    }
    println(Math.max(0, minR - maxL + 1))
}