#include <bits/stdc++.h>
#define SZ(x) ((int)x.size())
#define ALL(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef long double ld;
int n;
ll x[100010], v[100010], D[100010], E[100010], C;
int main() {
	scanf("%d%lld", &n, &C);
	for(int i=1; i<=n; i++)
		scanf("%lld%lld", x+i, v+i);
	ll res = 0;
	for(int i=1; i<=n; i++) {
		v[i] += v[i-1];
		D[i] = max(D[i-1], v[i] - x[i]);
		res = max(res, D[i]);
	}
	for(int i=n; i>=1; i--) {
		E[i] = max(E[i+1], v[n] - v[i-1] - (C - x[i]));
		res = max(res, v[n] - v[i-1] - (C - x[i]));
	}
	for(int i=1; i<=n; i++) {
		res = max(res, D[i] - x[i] + E[i+1]);
		res = max(res, E[i] - (C - x[i]) + D[i-1]);
	}
	printf("%lld", res);
	return 0;
}