import java.util.Scanner

fun main(args : Array<String>) {
        val scn = Scanner(System.`in`)
        val N = scn.nextInt()
        val M = scn.nextInt()

        var L = Int.MIN_VALUE
        var R = Int.MAX_VALUE

        for (i in 1..M) {
                val lm = scn.nextInt()
                val rm = scn.nextInt()
                L = if (L < lm) lm else L
                R = if (rm < R) rm else R
        }
        val ans = R - L + 1
        if (ans > 0) {
                println(ans)
        }
        else {
                println(0)
        }
}
