#include<iostream>
#include<cstring>
#include<cstdio>
#define N (200000+1000)
using namespace std;
long long n,m,a[N],b[N],ans,s1[N],s2[N];
int main()
{
	scanf("%lld%lld",&n,&m);
	for (int i=1; i<=n; ++i)
		scanf("%lld%lld",&a[i],&b[i]);
	
	long long last=0,sum=0;
	for (int i=1; i<=n; ++i)
	{
		sum=sum-(a[i]-last)+b[i];
		last=a[i];
		s1[i]=max(s1[i-1],sum);
		ans=max(ans,sum);
	}
	
	last=m,sum=0;
	for (int i=n; i>=1; --i)
	{
		sum=sum-(last-a[i])+b[i];
		last=a[i];
		s2[i]=max(s2[i+1],sum);
		ans=max(ans,sum);
	}
	
	last=0,sum=0;
	for (int i=1; i<=n-1; ++i)
	{
		sum=sum-(a[i]-last)*2+b[i];
		last=a[i];
		ans=max(ans,sum+s2[i+1]);
	}
	
	last=m,sum=0;
	for (int i=n; i>=2; --i)
	{
		sum=sum-(last-a[i])*2+b[i];
		last=a[i];
		ans=max(ans,sum+s1[i-1]);
	}
	printf("%lld",ans);
}