function Main(input) {
	tmp = input.split("\n");
	a = tmp[0].split(" ");
	var n = parseInt(a[0]);
	var m = parseInt(a[1]);
	var r = 0;
	
	for (var i = 1 ; i <= n ; i++){
		dame = 0;
		for (var j = 1 ; j <= m ; j++){
			var b = tmp[j].split(" ");
			var bl = parseInt(b[0]);
			var br = parseInt(b[1]);
			if(i < bl || i > br){ dame++; }
		}
		if(dame == 0){
			r++;
		}
	}
	console.log(r);
}

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