object Main {
  def main(args:Array[String]) = {
    val sc = new java.util.Scanner(System.in)
    val n,m = sc.nextInt
    var l: List[Int] = List.empty
    var r: List[Int] = List.empty
    for(i <- 0 until m){
      l = l :+ sc.nextInt
      r = r :+ sc.nextInt
    }
    val result = r.min - l.max + 1
    if(result > 0){
      println(result)
    }else{
      println(0)
    }
  }
}
