// C - Prison
#include <bits/stdc++.h>
using namespace std;

int in(){int x;scanf("%d",&x);return x;}

int main(){
	int N=in(), M=in();
	int L = 1, R = N;
	while(M--){
		L = max(L, in());
		R = min(R, in());
	}
	cout<< (R<L? 0: R-L+1) <<endl;
}