#include<bits/stdc++.h>
#define rep(i,a,b) for (int i=(a); i<=int(b); i++)
#define per(i,a,b) for (int i=(a); i>=int(b); i--)
using namespace std;
typedef long long LL;

const int maxn = 100005;
LL pre[maxn], suf[maxn], x[maxn], v[maxn], ans, best, C;
int n;

int main() {
	scanf("%d%lld", &n, &C);
	rep (i, 1, n) scanf("%lld%lld", &x[i], &v[i]);
	rep (i, 1, n) pre[i] = pre[i-1] + v[i];
	per (i, n, 1) suf[i] = suf[i+1] + v[i];
	per (i, n, 1) {
		ans = max(ans, best + pre[i] - x[i]);
		best = max(best, 2 * (x[i] - C) + suf[i]);
		ans = max(ans, x[i] - C + suf[i]);
	}
	best = 0;
	rep (i, 1, n) {
		ans = max(ans, best + suf[i] + x[i] - C);
		best = max(best, - 2 * x[i] + pre[i]);
		ans = max(ans, - x[i] + pre[i]);
	}
	printf("%lld\n", ans);
	return 0;
}