import kotlin.comparisons.*
import java.util.*

const val MOD = 1000000007L

fun readI() = readLine()!!.toInt()
fun readL() = readLine()!!.toLong()
fun readD() = readLine()!!.toDouble()
fun readIs() = readLine()!!.split(' ').map(String::toInt)
fun readLs() = readLine()!!.split(' ').map(String::toLong)
fun readDs() = readLine()!!.split(' ').map(String::toDouble)
fun max(a: Int, b: Int) = Math.max(a, b)
fun min(a: Int, b: Int) = Math.min(a, b)

fun main(args: Array<String>) {
  val (n, m) = readIs()
  var a = 0
  var b = Int.MAX_VALUE
  repeat(m) {
    val (l, r) = readIs()
    a = max(a, l)
    b = min(b, r)
  }
  println(max(0, b - a + 1))
}
