#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
ll n,c,i,x[101010],v[101010],tem,ma1[101010],ma2[101010],has;
int main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n>>c;
	for(i=1;i<=n;i++)
		cin>>x[i]>>v[i];
	for(i=1;i<=n;i++)
	{
		tem+=v[i];
		ma1[i]=max(ma1[i-1],tem-x[i]);
		has=max(has,ma1[i]);
	}
	tem=0;
	for(i=n;i>=1;i--)
	{
		tem+=v[i];
		ma2[i]=max(ma2[i+1],tem-(c-x[i]));
		has=max(has,ma2[i]);
	}
	for(i=1;i<n;i++)
	{
		has=max(has,ma1[i]+ma2[i+1]-x[i]);
	}
	for(i=n;i>=2;i--)
	{
		has=max(has,ma2[i]+ma1[i-1]-(c-x[i]));
	}
	cout<<has<<"\n";
}