#include <iostream>
#include <algorithm>
using namespace std;

long long N, C, x[100009], v[100009], s1[100009], maxn = -(1LL << 60);

long long solve() {
	for (int i = 0; i <= N; i++) s1[i] = -(1LL << 60);
	long long G = 0, ret = 0;
	for (int i = 1; i <= N; i++) {
		G += v[i];
		s1[i] = max(s1[i - 1], G - x[i]);
	}
	ret = max(ret, s1[N]);
	long long Z = 0;
	for (int i = N; i >= 1; i--) {
		Z += v[i];
		ret = max(ret, s1[i - 1] + (Z - (C - x[i]) * 2));
	}
	return ret;
}

int main() {
	cin >> N >> C;
	for (int i = 1; i <= N; i++) cin >> x[i] >> v[i];

	for (int i = 0; i < 2; i++) {
		maxn = max(maxn, solve());
		for (int j = 1; j <= N; j++) x[j] = C - x[j];
		reverse(x + 1, x + N + 1);
		reverse(v + 1, v + N + 1);
	}
	cout << maxn << endl;
	return 0;
}