object Main {
  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)
    val N = sc.nextInt
    val M = sc.nextInt
    val L = new Array[Int](M)
    val R = new Array[Int](M)
    for (i <- 0 until M) {
      L(i) = sc.nextInt
      R(i) = sc.nextInt
    }

    val maxL = L.max
    val minR = R.min

    val ans =
      if (maxL <= minR) {
        minR - maxL + 1
      } else {
        0
      }

    println(ans)
  }
}