#include <iostream>
using namespace std;
int n,m;
int r[100005];
int l[100005];
int main(){
	cin>>n>>m;
	int maxl=0,minr=99999999;
	for(int i=1;i<=m;i++){
		cin>>l[i]>>r[i];
		maxl=max(maxl,l[i]);
		minr=min(minr,r[i]);
	}
	cout<<max(minr-maxl+1,0);
	return 0;
}