#include<bits/stdc++.h>
using namespace std;
#define int long long
void solve()
{
int n,m;
cin>>n>>m;
map<int,int>mp;
for(int i=1;i<=m;i++)
{
int l,r;
cin>>l>>r;
mp[l]++,mp[r+1]--;
}
int now=0;
int maxn=0,pre=0;
for(auto&pair:mp)
{
if(now==0)
{
maxn=max(maxn,pair.first-pre);
}
now+=pair.second;
if(now==0)pre=pair.first;
}
if(now==0)
{
maxn=max(maxn,n+1-pre);
}
cout<<maxn<<"\n";
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
int t=1;
//cin>>t;
while(t--)
{
solve();
}
return 0;
}