fun main (args : Array<String>) {
	val (n, m) = readLine()!!.split(" ").map(String::toInt)
	val N : Int = n.toInt()
	val M : Int = m.toInt()
	var L : Int
	var R : Int
	val lList : MutableList<Int> = mutableListOf()
	val rList : MutableList<Int> = mutableListOf()
	var result : Int = 0
	for (i in 0..M - 1) {
		val (l, r) = readLine()!!.split(" ").map(String::toInt)
		L = l.toInt()
		R = r.toInt()
		lList.add(L)
		rList.add(R)
	}
	lList.sort()
	lList.reverse()
	rList.sort()
	for (i in lList[0]..rList[0]) {
		result++
	}
	println("${result}")
	
}