process.stdin.resume();
process.stdin.setEncoding('utf8'); 
var lines = [];
var reader = require('readline').createInterface({
	input: process.stdin,
	output: process.stdout
});
 
reader.on('line', (line) => {
	lines.push(line);
});

reader.on('close', () => {
	"use strict"
	const N = +lines[0].split(" ")[0];
	const M = +lines[0].split(" ")[1];
	const L = Array.from(Array(M), (e,i) => 
		+lines[i+1].split(" ")[0]);
	const R = Array.from(Array(M), (e,i) => 
		+lines[i+1].split(" ")[1]);
	
	const max_L = L.reduce((a,b) => Math.max(a,b), 1);
	const min_R = R.reduce((a,b) => Math.min(a,b), N);
	
	if(max_L>min_R){console.log(0)}
	else{console.log(min_R-max_L+1)}
});