object Main extends App {
	val Array(n, m) = scala.io.StdIn.readLine.split(" ").map(_.toInt)
	val tL = new Array[Int](m)
	val tR = new Array[Int](m)

	for(i<-0 until m){
		val Array(tp1, tp2) = scala.io.StdIn.readLine.split(" ").map(_.toInt - 1)
		
		tL(i) = tp1
		tR(i) = tp2

	}

	val maxL = tL.max
	val maxR = tR.min

	val ans = maxR - maxL + 1

	println(math.max(0, ans))
}