object Main extends App {
    val Array(n, m) = io.StdIn.readLine.split(" ").map(_.toInt)
    val lrs = for (_ <- 1 to m) yield io.StdIn.readLine.split(" ").map(_.toInt)

    /* TLE case
    // (L_i to R_i)
    val indexedseqs = lrs.map(lr => lr.head to lr.last).map(_.toIndexedSeq)
    // compute intersect
    val numberPassAllGate = indexedseqs.reduce((a,b) => a.intersect(b))

    println(numberPassAllGate.length)
    */

    // L_max and R_min
    val L_max = lrs.map(_.head).max
    val R_min = lrs.map(_.last).min

    val range = R_min - L_max + 1
    println(range)
}