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 = 0
    for(a <- array) {
      if (a(0) > l) { l = a(0).toInt }
      if (a(1) > r) { r = a(1).toInt }
    }
    println(Array(l to r).length)
  }
}