#include <bits/stdc++.h>

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)

using namespace std;

typedef long long ll;

const int MAX_N=1e5;
const ll INF=1e18;

int N;
ll C;
ll X[MAX_N+2],V[MAX_N+2];
ll vsum[MAX_N+2];

int main(){
	cin>>N>>C;
	vsum[0]=0;
	X[0]=0;
	V[0]=0;
	REP(i,N){
		cin>>X[i+1]>>V[i+1];
		vsum[i+1]=vsum[i]+V[i+1];
	}
	ll ans=-INF;
	int mx1,mx2;
	mx1=0;
	mx2=0;
	int y=0;
	REP(i,N){
		y++;
		ll ans2;
		if (vsum[mx1]-X[mx1]<vsum[i]-X[i]){
			mx1=i;
		}
		if (vsum[mx2]-2*X[mx2]<vsum[i]-2*X[i]){
			mx2=i;
		}
		if (X[mx1]>=C-X[y]){
			ans2=vsum[mx1]+(vsum[N]-vsum[y-1])-X[mx1]-(C-X[y])-min<ll>(X[mx1],C-X[y]);
		}else{
			ans2=vsum[mx2]+(vsum[N]-vsum[y-1])-X[mx2]-(C-X[y])-min<ll>(X[mx2],C-X[y]);
		}
		ans=max<ll>(ans,ans2);
	}
	if (vsum[mx1]-X[mx1]<vsum[N]-X[N]){
		mx1=N;
	}
	ans=max<ll>(ans,vsum[mx1]-X[mx1]);
	mx1=0;
	mx2=0;
	int y=0;
	REP(i,N){
		y++;
		ll ans2;
		if (vsum[mx1]-X[mx1]<=vsum[i]-X[i]){
			mx1=i;
		}
		if (vsum[mx2]-2*X[mx2]<=vsum[i]-2*X[i]){
			mx2=i;
		}
		if (X[mx1]>=C-X[y]){
			ans2=vsum[mx1]+(vsum[N]-vsum[y-1])-X[mx1]-(C-X[y])-min<ll>(X[mx1],C-X[y]);
		}else{
			ans2=vsum[mx2]+(vsum[N]-vsum[y-1])-X[mx2]-(C-X[y])-min<ll>(X[mx2],C-X[y]);
		}
		ans=max<ll>(ans,ans2);
	}
	if (vsum[mx1]-X[mx1]<vsum[N]-X[N]){
		mx1=N;
	}
	ans=max<ll>(ans,vsum[mx1]-X[mx1]);
	cout<<ans<<endl;
	return 0;
}

/*
int main(){
	cin>>N>>C;
	vsum[0]=0;
	X[0]=0;
	V[0]=0;
	REP(i,N){
		cin>>X[i+1]>>V[i+1];
		vsum[i+1]=vsum[i]+V[i+1];
	}
	X[N+1]=C;
	V[N+1]=0;
	vsum[N+1]=vsum[N];
	ll ans=0;
	REP(i,N+1){
		FOR(j,i+1,N+2){
			ans=max(ans,vsum[i]+(vsum[N]-vsum[j-1])-X[i]-(C-X[j])-min(X[i],C-X[j]));
		}
	}
	cout<<ans<<endl;
	return 0;
}
*/