import java.util.Scanner


object Main extends App {

  def read(): (Int, Int, IndexedSeq[IndexedSeq[Int]]) = {
    val sc = new Scanner(System.in)
    val n, m = sc.nextInt()
    val rlArr: IndexedSeq[IndexedSeq[Int]] = IndexedSeq.fill(m, 2)(sc.nextInt())
    (n, m, rlArr)
  }

  def solve() = {
    val (n, m, arr) = read()
    var maxL = 1
    var minR = n
    arr.foreach { list =>
      maxL = Math.max(maxL, list.head)
      minR = Math.min(minR, list.last)
    }
    if(maxL < minR) minR - maxL + 1
    else 0
  }


  println(solve)

}