#include<cstdio>
#include<algorithm>
#define LL long long
using namespace std;

const int N=100005;
int n;
LL C,ans,x[N],v[N],ssum[N],nsum[N],smx1[N],smx2[N],nmx1[N],nmx2[N];

int main(){
	scanf("%d%lld",&n,&C);
	for(int i=1;i<=n;++i)
		scanf("%lld%lld",&x[i],&v[i]);
	for(int i=1;i<=n;++i){
		ssum[i]=ssum[i-1]+v[i];
		smx1[i]=max(smx1[i-1],ssum[i]-x[i]);
		smx2[i]=max(smx2[i-1],ssum[i]-2*x[i]);
	}
	for(int i=n;i>=1;--i){
		nsum[i]=nsum[i+1]+v[i];
		nmx1[i]=max(nmx1[i+1],nsum[i]-(C-x[i]));
		nmx2[i]=max(nmx2[i+1],nsum[i]-2*(C-x[i]));
	}
	for(int i=0;i<=n;++i){
		ans=max(ans,smx1[i]);
		ans=max(ans,nmx1[i]);
		ans=max(ans,smx2[i]+nmx1[i+1]);
		ans=max(ans,smx1[i]+nmx2[i+1]);
	}
	printf("%lld\n",ans);
	return 0;
}