function Main(input) {
    array = input[0].split(" ");
    const M = array[1];
    var l = Array(M), r = Array(M),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);
    }
    l.sort((a,b)=>a<b?1:-1);
    r.sort((a,b)=>a<b?-1:1); 
    console.log(r[0]-l[0]+1>0?r[0]-l[0]+1:0);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8").split("\n"));