
function Main(input) {
    var N = parseInt(input[0], 10);
    var M = parseInt(input[1], 10);
    var LR = input.slice(2).map(v => parseInt(v, 10));

    var L = [];
    var R = [];

    LR.forEach((value, index) => {
        if (index % 2 === 0) {
            L.push(value);
        } else {
            R.push(value);
        }
    });

    var maxL = 0;
    for (var li = 0; li < L.length; li++) {
        maxL = maxL < L[li] ? L[li] : maxL;
    }
    var minR = 100000;
    for (var ri = 0; ri < R.length; ri++) {
        minR = minR > R[ri] ? R[ri] : minR;
    }

    if (maxL > minR) {
        console.log(0);
    } else {
        console.log(Math.abs(maxL - minR) + 1);
    }


}

Main(require("fs").readFileSync("/dev/stdin", "utf8").trim().split(/\n|\s/));