"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 count = 0
    var data = arg.map(e => e.split(" ").map(Number))
    for (var i = 0; i < n; i++) {
        var tmp = true
        for (var j = 0; j < m; j++) {
            var lj = data[j][0]
            var rj = data[j][1]
            if (!(lj <= i+1 && i+1 <= rj)) {
                tmp = false
            }
        }
        if (tmp) {
            count++
        }
    }
    console.log(count)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));
