import java.util.Scanner

object Main extends App{
  val sc = new Scanner(System.in)

  val n = sc.nextInt
  val m = sc.nextInt

  val lrSeq = Seq.fill(m)((sc.nextInt, sc.nextInt))

  val lM = lrSeq.map(_._1).max
  val rm = lrSeq.map(_._2).min

  val res =
    if(lM > rm) 0
    else rm - lM + 1

  println(res)
}
