"use strict";
function main(input) {
    const args = input.split("\n");
    const one = args[0].split(" ");
    const second = args[1].split(" ");

    const N = parseInt(one[0]);
    const M = parseInt(one[1]);

    let temp;
    let front;
    let end;
    let min = parseInt(second[0]);
    let max = parseInt(second[1]);

    for(let i = 2; i <= M; i++) {
        temp = args[i].split(" ");
        front = parseInt(temp[0]);
        end = parseInt(temp[1]);
        if(end < min) {
            max = -1;
            min = 0;
            break;
        } else if(front < min && end < max) {
            max = end;
        } else if(min < front && end < max) {
            min = front;
            max = end;
        } else if(front < min && max < end) {
            min = front;
        } else if(max < front) {
            max = -1;
            min = 0;
            break;
        }
    }
    console.log(max - min + 1)

}
main(require("fs").readFileSync("/dev/stdin", "utf8"));
