#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N=1e5+10;
struct T
{
	ll a,b;
}D[N];
ll A[N];
T stk[N];int cnt=0;
ll res[N];
int main()
{
	//freopen("/home/zz7/CFInput","r",stdin);
	ll n,c;scanf("%lld%lld",&n,&c);
	for(int i=1;i<=n;i++)scanf("%lld%lld",&D[i].a,&D[i].b);
	ll ans=0,f=0;D[n+1].a=c;
	for(int i=n;i>=1;i--){
		A[i]=A[i+1]+D[i].b-(D[i+1].a-D[i].a);
		if(A[i]>=ans)ans=A[i],stk[cnt++]={ans,i};
		f=max(f,A[i]-(c-D[i].a));res[i]=f;
	}
	for(int i=1;i<=n;i++){
		A[i]=A[i-1]+D[i].b-(D[i].a-D[i-1].a);
		while(cnt>0&&stk[cnt-1].b<=i)cnt--;
		if(cnt>0){
			ll op=A[i]-D[i].a+stk[cnt-1].a;
			ll op1=A[i]+res[i+1];
			ans=max(ans,op);
			ans=max(ans,op1);
		}ans=max(ans,A[i]);
	}cout<<ans<<'\n';
}
