fun main(args: Array<String>) {
    val (n,m) = readLine()!!.split(" ").map { it.toInt() }
    val imos = IntArray(n+2){ 0 }
    repeat(m) {
        val (l,r) = readLine()!!.split(" ").map { it.toInt() }
        imos[l]++
        imos[r+1]--
    }
    val ans = imos.toList().summed().count{it==m}
    println(ans)
}

inline fun List<Int>.summed() = { var sum = 0; this.map { sum += it; sum } }()
