import scala.io.StdIn


object Main extends App {
  val Array(n, m)  = StdIn.readLine.split(" ").map(_.toInt)
  val Array(l, r)  = StdIn.readLine.split(" ").map(_.toInt)
  var ret :Array[Int]= Array(l, r)

  (2 to m).foreach { i =>
    val Array(l, r)  = StdIn.readLine.split(" ").map(_.toInt)

    if (ret(0) < l)
      ret(0) = l

    if (ret(1) > r)
      ret(1) = r
  }

  println(ret(1) - ret(0) + 1)
}
  

