fun main(args:Array<String>) {
    val (n,m) = readLine()!!.split(" ").map { it.toInt() }
    val gateList = (1..m).map { readLine()!!.split(" ").map { it.toInt() } }
    val lMax = gateList.map { it[0] }.max()!!
    val rMin = gateList.map { it[1] }.min()!!
    val ans = Math.max(0, rMin - lMax + 1)
    println(ans)
}