"use strict"
function main(arg) {
    arg = arg.trim().split("\n")
    var nm = arg.shift().split(" ").map(Number)
    var n = nm[0]
    var m = nm[1]
    var data = arg.map(e => e.split(" ").map(Number))
    var result = Array.from(new Array(n), () => new Array(m).fill(false));
    // var bucketL = {}
    // var bucketR = {}
    // for (var i = 0; i < data.length; i++) {
    //     bucketL[data[i][0]] = i
    //     bucketR[data[i][1]] = i
    // }
    // for (var i = 1; i <= n; i++) {
    //     var t = bucketR[i]
    //     console.log(t)
    // }
    for (var i = 0; i < m; i++) {
        var ri = data[i][1]
        var li = data[i][0]
        result[ri - 1][i] = true
        for (var j = li; j < n; j++) {
            result[j - 1][i] = true
        }
    }
    var count = 0;
    for (var i = 0; i < result.length; i++) {
        var tmp_flg = true
        for (var j = 0; j < result[i].length; j++) {
            if (!result[i]) {
                tmp_flg = false
                break
            }
        }
        if (tmp_flg) {
            count++
        }
    }
    console.log(count)
    // console.log(JSON.stringify(result, null, '\t'))
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));