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

int main()
{
	int n, m;
	cin >> n >> m;
	int b = 1, e = n;
	for(auto i = 0; i < m; ++i){
		int l, r;
		cin >> l >> r;
		b = max(b, l);
		e = min(e, r);
	}
	cout << max(0, e - b + 1) << endl;
	return 0;
}