#include<iostream>
#include<cstdio>
using namespace std;
const int maxn=100000+10;
int n;
long long c,mx,x[maxn],v[maxn],a[maxn],b[maxn],i;
int main()
{
	cin>>n>>c;
	for (i=1;i<=n;i++) 
	{
		cin>>x[i]>>v[i];
		a[i]=a[i-1]+x[i-1]-x[i]+v[i];
	}
	x[n+1]=c;
	for (i=n;i>=1;i--)
	{
		b[i]=b[i+1]+x[i]-x[i+1]+v[i];
	}
	for (i=2;i<=n;i++)
	{
		a[i]=max(a[i],a[i-1]);
	}
	for (i=n-1;i>=1;i--)
	{
		b[i]=max(b[i],b[i+1]);
	}
	for (i=1;i<=n;i++)
	{
		mx=max(mx,a[i]),mx=max(mx,b[i]);
		mx=max(mx,a[i]-x[i]+b[i+1]);
		mx=max(mx,b[i]-(c-x[i])+a[i-1]);
	}
	cout<<mx<<endl;
	return 0;
}