import scala.io.{StdIn => in}

object Main extends App {
  val Array(n, m) = in.readLine.split(" ").map(_.toInt)

  val (l, r) = (1 to m)./:((0,n)) { (acc, e) =>
    val Array(l, r) = in.readLine.split(" ").map(_.toInt)
    (acc._1 max l, acc._2 min r)
  }

  val ans = r - l + 1
  println(ans)
}