#include<iostream>
#include<map>
using namespace std;
int main(){
int number,frequency,j,left,right,q,count=0,i;
map<int,int> mp1;
cin>>number>>frequency;
for ( i = 0; i <= number; i++)
{
mp1.insert({i,1});
}
for ( j = 0; j < frequency; j++)
{
cin>>left>>right;
for ( q = left; q <= right; q++)
{
mp1.erase(q);
mp1.insert({q,0});
}
}
for ( i = 0; i <= number; i++)
{
if (mp1[i]==1)
{
count++;
}
}
cout<<count;
return 0;
}