#include<bits/stdc++.h>
using namespace std;
int n,m,maxn=0,minn=99999999;
int main(){
	cin>>n>>m;
	for(int i=1,j,k;i<=m;i++){
		cin>>j>>k;
		maxn=max(maxn,j);
		minn=min(minn,k);
	}
	if(minn-maxn+1<=0)cout<<'0';
	else cout<<minn-maxn+1;
	return 0;
}