fun main(args: Array<String>): Unit {
    val sc = java.util.Scanner(System.`in`)
    val n = sc.nextInt()
    val m = sc.nextInt()

    var L = 0
    var r = Int.MAX_VALUE
    for (i in 0 until m) {
        L = Math.max(L, sc.nextInt())
        r = Math.min(r, sc.nextInt())
    }
    println(Math.max(r - L + 1, 0))
}
