function Main(input) {
    input = input.trim().split("\n");
    tmp = input[0].split(" ");
    var N = parseInt(tmp[0],10);
    var M = parseInt(tmp[1],10);
    var L = [];
    var R = [];
    var output;
    var maxL = 1;
    var minR = N;

    for(var i = 1; i <= M; i++){
        L[i-1] = parseInt(input[i].split(" ")[0],10);
        R[i-1] = parseInt(input[i].split(" ")[1],10);
        if(maxL < L[i-1]){
            maxL = L[i-1];
        }
        if(minR > R[i-1]){
            minR = R[i-1];
        }
    }
    output = minR - maxL + 1;
    if(output < 0){
        output = 0;
    }
    console.log(output);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));