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

int main() {
	int n, m, l, r;
	cin >> n >> m;
	int inf = 1, sup = n;
	for (int i = 0; i < m; i++) {
		cin >> l >> r;
		if (l > inf)
			inf = l;
		if (r < sup)
			sup = r;
	}
	cout << max(sup - inf + 1, 0) << endl;
}
