#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define mod 1000000007
#define pb push_back
#define pi pair<int,int>
#define vi vector<int>
#define vpi vector< pi >
const int N=200010;
ll x[N],v[N],ans[N];
int main()
{
	ll n,c;
	cin>>n>>c;
	for(int i=1;i<=n;i++) cin>>x[i]>>v[i];
	//for(int i=1;i<=n;i++) cin>>v[i];
	ll res=0,r=0;
	for(ll i=n;i>0;i--)
	{
		if(i==n)
		r-=(c-x[i]);
		else
			r-=(x[i+1]-x[i]);
		r+=v[i];
		ans[i]=max(ans[i+1],r);
		res=max(res,ans[i]);
	}
	r=0;
	for(ll i=1;i<=n;i++)
	{
		if(i==1)
			r-=x[i];
		else
			r-=(x[i]-x[i-1]);
		r+=v[i];
		res=max(res,max(r,r+ans[i+1]-x[i]));
		ans[i]=max(ans[i-1],r);
	}
	r=0;
	for(ll i=n;i>0;i--)
	{
		if(i==n)
		r-=(c-x[i]);
		else
			r-=(x[i+1]-x[i]);
		r+=v[i];
		res=max(res,r+ans[i-1]-(c-x[i]));
	}
	//cout<<ans[0]<<ans[n+1]<<"\n";
	cout<<res;
	return 0;
}