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)
    solution(l, r)
  }
  def solution(l : Int, r: Int) : Unit = {
    if (ret(0) <= l && ret(1) >= l )
      ret(0) = l

    if (ret(0) <= r && ret(1) >= r)
      ret(1) = r

    if (ret(0) > r || ret(1) < l) {
      println(0)
      return
    }
  }

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

