import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val Array(n, m) = sc.nextLine.split(" ").map(_.toInt)
    val gateRanges = List.fill(m)(sc.nextLine.split(" ").map(_.toInt))
    val intersectionNumber = gateRanges.scanLeft((1 to n).toArray) {
      (acc, gateRange) => {
        if (acc.isEmpty) acc
        else if(acc.min > gateRange.last | acc.max < gateRange.head) Array()
        else acc intersect (gateRange.head to gateRange.last)
      }
    }
    intersectionNumber.find(_.length == 0) match {
      case Some(s) => println(0)
      case None => println(intersectionNumber.last.length)
    }
  }
}