#include "bits/stdc++.h"
using namespace std;
typedef long long LL;
LL x[100010], v[100010];
LL a[100010], b[100010];
int main() {
	int N;
	LL C;
	cin >> N >> C;
	for (int i = 1; i <= N; i++) cin >> x[i] >> v[i];
	x[N + 1] = C;
	for (int i = 1; i <= N; i++) a[i] = a[i - 1] + v[i] - (x[i] - x[i - 1]);
	for (int i = 1; i <= N; i++) a[i] = max(a[i], a[i - 1]);
	for (int i = N; i >= 1; i--) b[i] = b[i + 1] + v[i] - (x[i + 1] - x[i]);
	for (int i = N; i >= 1; i--) b[i] = max(b[i], b[i + 1]);
	LL ans = 0;
	for (int i = 1; i <= N; i++) {
		ans = max(ans, a[i]);
		ans = max(ans, b[i]);
		ans = max(ans, a[i] + b[i + 1] - x[i]);
		ans = max(ans, b[i] + a[i - 1] - (C - x[i]));
	}
	cout << ans << endl;
}