import std.stdio, std.conv, std.string, std.math, std.regex, std.range, std.ascii, std.algorithm;

void main(){
	auto ip = readln.split.to!(int[]), N=ip[0], M=ip[1];
	auto start = readln.split.to!(int[]);
	int L = start[0];
	int R = start[1];
	foreach(i; 0..M){
		auto LR = readln.split.to!(int[]);
		if(L < LR[0]) L = LR[0];
		if(LR[1] < R) R = LR[1];
		if(L==R) break;
	}
	if(R==L) writeln(1);
	else writeln(R-L);
}