object Main {
  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)
    val n,m = sc.nextInt
    val array = Array.fill(m,2)(sc.nextInt)
    var l, r = List[Int]()
    for(a <- array) {
      l = l :+ a(0).toInt
      r = r :+ a(1).toInt
    }
    println(Array(l.max to r.min).length)
  }
}
