fun main(args: Array<String>) {
    val (N,M) = readLine()!!.split(" ").map { it.toInt() }
    var max=N
    var min = 1
    for (i in 0 until M){
        val (L,R) = readLine()!!.split(" ").map { it.toInt() }
        if(min<L)min=L
        if(max>R)max=R
    }
    print(if (max>=min)max-min+1 else 0)
}
