object Main {
  def main(args:Array[String]) = {
    val sc = new java.util.Scanner(System.in)
    val n,m = sc.nextInt
    var l: Array[Int] = Array.empty
    var r: Array[Int] = Array.empty
    for(i <- 0 until m){
      l = l :+ sc.nextInt
      r = r :+ sc.nextInt
    }
    var start = l(0)
    var last = r(0)

    for(i <- 1 until m){
      if(start < l(i)){
        start = l(i)
      }
      if(last > r(i)){
        last = r(i)
      }
    }

    if(last >= start){
      println(last - start + 1)
    }else{
      println(0)
    }
  }
}
