fun main(args: Array<String>) {

    val (idCardAmount, gateAmount) = readLine()!!.split(" ").map { Integer.parseInt(it) }
    val L = mutableListOf<Int>()
    val R = mutableListOf<Int>()
    val i = 0
    val LRList = mutableListOf<Pair<Int, Int>>()

    for (i in 0 until gateAmount) {
        val (L_, R_) = readLine()!!.split(" ").map { Integer.parseInt(it) }
        L.add(L_)
        R.add(R_)
        LRList.add(Pair(L_, R_))
    }
    val LMax = L.max()
    val RMin = R.min()
    LMax?.let {
        RMin?.let {
            print(Math.max(RMin - LMax + 1, 0))
        }
    }
}