fun main(args:Array<String>) {
    val (cardCount, gateCount) = readLine()!!.split(" ").map { it.toInt() };
    var fromNum = 1
    var toNum = cardCount

    for(i in (1..gateCount)) {
        val(l,r) = readLine()!!.split(" ").map { it.toInt() }

        if(fromNum > r || l > toNum) {
            println("0")
            return
        }

        fromNum = Math.max(fromNum, l)
        toNum = Math.min(toNum, r)
    }
    println(Math.max(toNum-fromNum + 1, 0))
}
