#include<iostream>
#include<cstdio>
using namespace std;
int main() {
	int n, m;
	int i, j;
	int l[100000] = { 0 };
	int r[100000] = { 0 };
	int f, c = 0;
	scanf("%d %d", &n, &m);
	for (i = 0; i < m; i++) {
		scanf("%d %d", &l[i], &r[i]);
	}
	for (i = 1; i <= n; i++) {
		f = 0;
		for (j = 0; j < m; j++) {
			if (l[j] <= i && i <= r[j])f++;
		}
		if (f == m)c++;
	}

	printf("%d\n", c);




	return 0;
}