#include<cstdio>
#include<cstring>
#include<iostream>

#define min(a,b) (a<b?a:b)
#define max(a,b) (a>b?a:b)

using namespace std;

const int maxn=1e5+10;

long long n,c,cnt,ans;
long long x[maxn],v[maxn],le[maxn],ri[maxn];

int main()
{
	scanf("%lld%lld",&n,&c);
	for(int i=1;i<=n;i++)
		scanf("%lld%lld",&x[i],&v[i]);
	
	for(int i=1;i<=n;i++)
		cnt+=v[i],le[i]=max(le[i-1],cnt-x[i]),ans=max(ans,le[i]);
	
	cnt=0;
	for(int i=n;i;i--)
		cnt+=v[i],ri[i]=max(ri[i+1],cnt-c+x[i]),ans=max(ans,ri[i]);
	
	cnt=0;
	for(int i=1;i<=n;i++)
	{
		cnt+=v[i];
		ans=max(ans,cnt-x[i]*2+ri[i+1]);
	}
	
	cnt=0;
	for(int i=n;i;i--)
	{
		cnt+=v[i];
		ans=max(ans,cnt-(c-x[i])*2+le[i-1]);
	}
	
	printf("%lld",ans);
	
	return 0;
}