fun main(args: Array<String>) {
    val (n, m) = readLine()!!.split(' ').map(String::toInt)
    var (l, r) = readLine()!!.split(' ').map(String::toInt)
    repeat(m - 1) {
        val (l2, r2) = readLine()!!.split(' ').map(String::toInt)
        l = Math.max(l, l2)
        r = Math.min(r, r2)
    }
    println(Math.max(r - l + 1, 0))
}
