import java.util.*

fun main(args: Array<String>) {
    val scanner = Scanner(System.`in`)
    scanner.nextInt()
    val m = scanner.nextInt()

    val ll = arrayListOf<Int>()
    val hl = arrayListOf<Int>()
    (1..m).forEach {
        ll.add(scanner.nextInt())
        hl.add(scanner.nextInt())
    }
    val lowMax = ll.max()!!
    val highMin = hl.min()!!
    if (lowMax > highMin)
        print(0)
    else
        print(highMin - lowMax + 1)
}
