object Main extends App {
 
  val sc = new java.util.Scanner(System.in) 
  val n, m = sc.nextInt()
  val g = Array.fill(m)((sc.nextInt(), sc.nextInt()))
  val max = g.map{ case (x, y) => x}.max
  val min = g.map{ case (x, y) => y}.min
  if (min < max) {
    println(0)
  } else {
    println(min - max + 1)
  }
}