#include<iostream>
#include<cstdio>
using namespace std;
bool t[10000];
int main()
{
int L,m,i,s=0,j,left,right;
scanf("%d%d",&L,&m);
for(j=0;j<=L;j++)
t[j]=0;
for(i=1;i<=m;i++)
{
cin>>left>>right;
for(j=left;j<=right;j++)
t[j]=1;
}
for(j=0;j<=L;j++)
{
if(t[j]==0)
s++;
}
printf("%d",s);
return 0;
}100'
#include<cstdio>
using namespace std;
bool t[10000];
int main()
{
int L,m,i,s=0,j,left,right;
scanf("%d%d",&L,&m);
for(j=0;j<=L;j++)
t[j]=0;
for(i=1;i<=m;i++)
{
cin>>left>>right;
for(j=left;j<=right;j++)
t[j]=1;
}
for(j=0;j<=L;j++)
{
if(t[j]==0)
s++;
}
printf("%d",s);
return 0;
}100'