function Main(input) {
    array = input[0].split(" ");
    const M = array[1];
    var l = Array(M), r = Array(M);
    var i;
    for (i = 0; i < M; i++) {
        var value = input[i+1].split(" ");
        l[i] = parseInt(value[0], 10);
        r[i] = parseInt(value[1], 10);
    }
    // console.log(r[M-1]);
    l.sort((a,b) => a < b ? 1 : -1);
    r.sort((a,b) => a < b ? -1 : 1);
    if (r[0]-l[0]+1 > 0) {
        console.log(r[0]-l[0]+1);
    } else {
        console.log(0);
    }
    // console.log(l);
    // console.log(r);    
}
Main(require("fs").readFileSync("/dev/stdin", "utf8").split("\n"));