"use strict";
    
const main = arg => {
    arg = arg.split("\n");
    const N = parseInt(arg[0].split(" ")[0]);
    const M = parseInt(arg[0].split(" ")[1]);
    
    const LR = arg.slice(1, M + 1);
    let low  = parseInt(LR[0].split(" ")[0]);
    let high = parseInt(LR[0].split(" ")[1]);
    
    for(let i in LR) {
        let L = parseInt(LR[i].split(" ")[0]);
        let R = parseInt(LR[i].split(" ")[1]);
        
        if(high < L) {
            console.log(0);
            return;
        }
        
        if(low > R) {
            console.log(0);
            return;
        }
        
        if(low < L) {
            low = L;
        }
        
        if(high > R) {
            high = R;
        }
    }

    
    console.log((high - low) + 1);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));