import scala.io.StdIn


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


  (1 to m).foreach { i =>
    val a  = StdIn.readLine.split(" ").map(_.toInt)
    l = l max a(0)
    r = r min a(1)

  }

  println((r - l + 1) max 0)
}
  

