import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val m = sc.nextInt()
    val lr = (0 until m).map {
        sc.next().toInt() to sc.next().toInt()
    }

    abc127c(n, m, lr)
}

fun abc127c(n: Int, m: Int, lr: List<Pair<Int, Int>>){
    var mn = 1
    var mx = n
    for (i in 0 until m) {
        var lri = lr.get(i)
        mn = Math.max(mn, lri.first)
        mx = Math.min(mx, lri.second)
    }

    var ans = mx - mn + 1
    if (ans < 0) {
        ans = 0
    }
    println(ans)
}
