#include<iostream>
#include<algorithm>
using namespace std;
#define i64 long long int
#define ran 100010
int N;i64 C;
i64 pos[ran], val[ran], lef[ran], rig[ran], lef2[ran], rig2[ran];
int main(){
	ios::sync_with_stdio(false);
	cin >> N >> C;
	for(int i=1; i<=N; i++)
		cin >> pos[i] >> val[i];

	i64 cur = 0;
	lef[0] = 0;
	for(int i=1; i<=N; i++){
		cur += val[i];
		lef[i] = max(lef[i-1], cur - pos[i]);
		lef2[i] = max(lef2[i-1], cur - 2 * pos[i]);
	}

	cur = 0;
	rig[0] = 0;
	for(int i=1; i<=N; i++){
		cur += val[N+1-i];
		rig[i] = max(rig[i-1], cur - (C - pos[N+1-i]));
		rig2[i] = max(rig2[i-1], cur - 2 * (C - pos[N+1-i]));
	}

	i64 res = 0;
	for(int i=1; i<=N; i++){
		res = max(res, lef[i] + rig2[N-i]);
		res = max(res, rig[i] + lef2[N-i]);
	}
	cout << res << endl;
	return 0;
}
