#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#define ll long long
using namespace std;

const int N=100005;
const ll inf=1000000000000000000ll;

int n;
ll ans,c,mx;
ll w[N],x[N],a[N],b[N],w1[N],w2[N];

int main(){
	int i;
	scanf("%d%lld",&n,&c);
	for (i=1;i<=n;i++) scanf("%lld%lld",&x[i],&w[i]);
	ans=0;
	for (i=1;i<=n;i++) w[i]+=w[i-1];
	for (i=1;i<=n;i++){
		w1[i]=w[i]-x[i];
		w2[i]=w[n]-w[i-1]-(c-x[i]);
		a[i]=w1[i]-x[i];
		b[i]=w2[i]-(c-x[i]);
		ans=max(ans,w1[i]);
		ans=max(ans,w2[i]);
	}
	mx=0;
	for (i=1;i<=n;i++){
		ans=max(ans,mx+w2[i]);
		mx=max(mx,a[i]);
	}
	mx=0;
	for (i=n;i>=1;i--){
		ans=max(ans,mx+w1[i]);
		mx=max(mx,b[i]);
	}
	printf("%lld\n",ans);
	return 0;
}