import java.util.*
fun main(args:Array<String>) {
    val (N,M) = readLine()!!.split(" ").map(String::toInt)
    val passibles = (1..M).map {
        val (l,r ) = readLine()!!.split(" ").map(String::toInt)
        Pair(l,r)
    }

    // var intersection = Array(N) {false}
    
    var result = Pair(1,N)
    for(nos in passibles) {
        val (l,r) = nos
        if( r < result.first || l > result.second) {
            result = Pair(0,0)
            break
        }
        result = when(Pair(l > result.first, r < result.second)) {
            Pair(false,false) -> result
            Pair(true,false) -> Pair(l,result.second)
            Pair(false,true) -> Pair(result.first,r)
            else -> Pair(l,r)
        }
    }

    if(result == Pair(0,0)) {0} else {
        result.second - result.first + 1 
    }.run(::println)
}