#include <iostream>
using namespace std;
int main()
{
	int L, M;
	int a[10001] = { 0 };
	scanf("%d %d", &L, &M);
	for (int i = 0; i < M; i++)
	{
		int left, right;
		scanf("%d %d", &left, &right);
		for (int j = left; j <=right; j++)
		{
			a[j] = 1;
		}
	}
	int num = 0;
	for (int j = 0; j < L+1; j++)
	{
		if (a[j] == 0)
			num++;
	}
	printf("%d\n", num);
	return 0;
}