var lines = [];

var readline = require('readline')
var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
});


rl.on('line', (x) => {
    lines.push(x)
});

rl.on('close', () => {
    var N = Number(lines[0].split(" ")[0])
    var M = Number(lines[0].split(" ")[1])
    lines.shift()

    var LR = lines.map(i => i.split(" ").map(i => Number(i)));
    var start = 1; var goal = Infinity;

    for (var i = 0; i < M; i++) {
        var l = LR[i][0]; var r = LR[i][1];

        if (goal < l || r < start) { console.log(0); return (0) }
        if (start < l) { start = l; }
        if (r < goal) { goal = r; continue; }

    }

    console.log(goal - start + 1)
});