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

	for(i<-0 until m){
		val Array(tp1, tp2) = scala.io.StdIn.readLine.split(" ").map(_.toInt - 1)
		
		for(j<-tp1 to tp2){
			ans(j) += 1
		}

	}

	println(ans.filter(_ == m).size)
}