fun main(args: Array<String>) {
	val (n, m) = (readLine() ?: return).split(" ").map { it.toInt() }.toIntArray()
	var min = 0
	var max = n
	for (i in 0 until m) {
		val (l, r) = (readLine() ?: return).split(" ").map { it.toInt() }.toIntArray()
		min = Math.max(min, l)
		max = Math.min(max, r)
	}
	if (max - min + 1 < 0) println(0)
	else println(max - min + 1)
}