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()
    val default: Seq[Int] = arr.head.head to arr.head.last
    arr.foldLeft(default) { (acc, list) =>
      val range = list.head to list.last
      acc.intersect(range)
    }.length
  }


  println(solve)

}
