#include<iostream>
#include<algorithm>
using namespace std ;

int main(){
	int n,m,l,r ;
	cin >> n >> m ;
	l = 0 ; r = 10000000 ;
	for(int i=0;i<m;i++){
		int subl,subr ;
		cin >> subl >> subr ;
		l = max(l,subl) ;
		r = min(r,subr) ;
	}
	cout << max(0,r-l+1) << endl ;
}