import java.util.*

fun main(args : Array<String>) {
  var (n, m) = readLine()!!.split(' ').map(String::toInt)
  var s = 0
  var e = n + 1
  repeat(m) {
    val (l, r) = readLine()!!.split(' ').map(String::toInt)
    s = Math.max(s, l)
    e = Math.min(e, r)
  }
  println(Math.max(e - s + 1, 0))
}
