import java.util.*

fun main(args:Array<String>){
    val (n,m) = readLine()!!.split(" ").map{it.toInt()}
    var a = IntArray(100010)
    repeat(m){
        val (l,r) = readLine()!!.split(" ").map{it.toInt()}
        a[l]++
        a[r + 1]--
    }
    for(i in 1 .. n){
        a[i] += a[i - 1]
    }
    var ans = 0
    for(i in 1 .. n){
        if(a[i] == m) ans++
    }
    println(ans)
}
