#include<iostream>
#include<algorithm>
using namespace std;
int n;
long c,x[1<<17],v[1<<17];
int main()
{
	cin>>n>>c;
	long ans=0,L=0,R=0,Rmax=0;
	for(int i=0;i<n;i++)
	{
		cin>>x[i]>>v[i];
		L+=v[i];
	}
	ans=L-x[n-1];
	for(int i=n;i--;)
	{
		L-=v[i];
		R+=v[i];
		Rmax=max(Rmax,R-(c-x[i]));
		ans=max(ans,L-(i?x[i-1]*(Rmax?2:1):0)+Rmax);
	}
	long Lmax=0;
	for(int i=0;i<n;i++)
	{
		L+=v[i];
		R-=v[i];
		Lmax=max(Lmax,L-x[i]);
		ans=max(ans,R-(i!=n-1?(c-x[i+1])*(Lmax?2:1):0)+Lmax);
	}
	cout<<ans<<endl;
}
