object Main extends App{
  import scala.io.StdIn._
  val Array(n,m) = readLine().split(" ").map(_.toLong)
  var Array(l,r) = readLine().split(" ").map(_.toLong)
  var flag = true
  for (i <- 1L until(m)){
    val Array(ll,rr) = readLine().split(" ").map(_.toLong)
    if(flag){
      if(l <= ll && r >= ll || ll <= l && rr >= l) {
      l = Math.max(l,ll)
      r = Math.min(r,rr)
      }else {
        flag = false
      }
    }
  }
  println(if(flag)r - l + 1 else 0)
}