fun main(args : Array<String>) {
    val (N, M) = readLine()!!.split(" ").map { it.toInt() }

    val lAndR = mutableListOf<Pair<Int, Int>>()
    (1..M).forEach {
        val (L, R) = readLine()!!.split(" ").map { it.toInt() }
        lAndR.add(Pair(L, R))
    }
    var commonRangeFrom = lAndR[0].first
    var commonRangeTo = lAndR[0].second

    (lAndR).forEachIndexed { index, pair ->
        if (index != 0) {
            val l = pair.first
            val r = pair.second

            var nextFrom = commonRangeFrom
            var nextTo = commonRangeTo
            // update from
            if (l <= commonRangeFrom) {
            } else if (commonRangeFrom < l && l <= commonRangeTo) {
                nextFrom = l
            } else {
                println(0)
                return
            }

            // update to
            if (commonRangeTo <= r) {
            } else if (commonRangeFrom <= r && r < commonRangeTo ) {
                nextTo = r
            } else {
                println(0)
                return
            }

            commonRangeFrom = nextFrom
            commonRangeTo = nextTo
        }
    }

    println(commonRangeTo - commonRangeFrom + 1)
}