#include <iostream>
using namespace std;

typedef long long ll;
int N;
ll C;

int main(){
	cin >> N >> C;
	int t = 0;
	ll X[N+2] = {0},V[N+1] = {0},Y[N+2] = {0},W[N+1] = {0};
	for(int i=1;i<=N;i++){
		cin >> X[i] >> V[i];
		Y[i] = C - X[i];
		W[N+1-i] = V[i];
		if(X[i]<=C/2) t++;
	}
	/*for(int i=1;i<=N;i++){
		if(X[i]+Y[N]<=X[i+1]-X[i])
	}*/
	//cout << C << endl;
	ll ans = 0;
	ll T[N+1] = {0};
	for(int i=1;i<=N;i++){
		T[i] = T[i-1] + V[i] -(X[i]-X[i-1]);
		ans = max(ans,T[i]);
	}
	//cout << T[1] << endl;
	/*cout << T[2] << endl;
	cout << T[3] << endl;*/
	ll S[N+2] = {0};
	X[N+1] = C;
	for(int i=1;i<=N;i++){
		S[N+1-i] = S[N+2-i] + V[N+1-i] + (X[N+1-i]-X[N+2-i]);
		ans = max(ans,S[N+1-i]);
	}
	/*cout << S[1] << endl;
	cout << S[2] << endl;*/
	//cout << S[3] << endl;
	//cout << ans << endl;
	//cout << t << endl;
	for(int i=1;i<=t;i++){
		for(int j=1;j<=N-t;j++){
			ans = max(ans,T[i] + S[N+1-j] - X[i]);
			ans = max(ans,T[i] + S[N+1-j] - Y[N+1-j]);
		}
	}
	cout << ans << endl;
}
