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