
#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};
	X[N+1] = C;
	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]) t++;
	}*/
	//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]);
	}
	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]);
	}
	for(int t=1;t<N;t++){
		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;
}
