// package abc127.c

import scala.io.StdIn

object Main {

  def main(args: Array[String]) {
    val Array(n, m) = StdIn.readLine().split(" ").map(e => e.toInt)
    val Array(l, r) = (1 to m).toList.foldLeft(Array(1, n))((arr, i) => {
      arr match {
        case Array(l, r) => {
          val Array(nl, nr) = StdIn.readLine().split(" ").map(e => e.toInt)
          Array(if (l < nl) nl else l, if (nr < r) nr else r)}
      }
    })
    val ans = r - l + 1
    println(if (ans < 0) 0 else ans)
  }

}
