#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF (1e9+1)
//#define INF (1LL<<59)


int main(){
	ll t;
	int n;
	cin>>t>>n;
	vector<ll> v;
	
	rep(i,n){
		ll a,b;
		cin>>a>>b;
		v.pb(a), v.pb(b);
	}
	
	int left = 0, right = 0;// (0,0)
	ll tmp = 0, ans = 0;

	while(left<=right){
		while( right+1<2*n && v[right+1] - v[left] <= t ){
			if((right+1)%2==1)tmp += v[right+1]-v[right];
			right++;
		}
		if(right%2==0)ans = max(ans,tmp+t-(v[right]-v[left]));
		else ans = max(ans,tmp);
		
		if(left%2==0)tmp -= v[left+1] - v[left];
		left++;
	}
	
	cout<<ans<<endl;
}