import scala.io.StdIn


object Main extends App {
  val Array(n, m)  = StdIn.readLine.split(" ").map(_.toInt)
  var ret = (1 to n).toSet

  (1 to m).foreach { i =>
    val Array(l, r)  = StdIn.readLine.split(" ").map(_.toInt)
    ret = ret.intersect((l to r).toSet)
  }

  println(ret.size)
}
  

