#include <stdio.h>
int main()
{
int L, M;
int nTrees[10005] = {0};
int start, end;
int nCount = 0;
scanf("%d%d", &L, &M);
while (M--)
{
scanf("%d%d", &start, &end);
for (int i = start; i <= end; ++i)
{
nTrees[i] = 1;
}
}
for (int i = 0; i <= L; ++i)
{
if (nTrees[i] == 0)
{
nCount++;
}
}
printf("%d\n", nCount);
return 0;
}
#include <stdio.h>
#include <stdlib.h>
#define M_MAX 100 + 2
struct Area{
int start;
int end;
};
int CompareArea(const void *elem1, const void *elem2)
{
return ((Area*)elem1)->start - ((Area*)elem2)->start;
}
int main()
{
Area area[M_MAX], temp;
int L = 0;
int M = 0;
int count = 0;
scanf("%d%d", &L, &M);
for (int i = 0; i < M; ++i)
{
scanf("%d%d", &area[i].start, &area[i].end);
}
qsort(area, M, sizeof(Area), CompareArea);
temp = area[0];
for (int i = 1; i < M; ++i)
{
if (area[i].start <= temp.end)
{
if (area[i].end > temp.end)
{
temp.end = area[i].end;
}
}
else
{
count += temp.end - temp.start + 1;
temp = area[i];
}
}
count += temp.end - temp.start + 1;
printf("%d\n", L + 1 - count);
return 0;
}