#include <stdio.h>
#include <algorithm>

using namespace std;

int main() {
	int l = 1, r, n, m, a, b;
	scanf("%d %d", &n, &m);
	r = n;
	while (m--) {
		scanf("%d %d", &a, &b);
		l = max(l, a);
		r = min(r, b);
	}
	n = max(0, r - l + 1);
	printf("%d\n", n);
	return 0;
}