#include <iostream>
#include <cstdio>
#define N 100005
using namespace std;
 
typedef long long ll;
ll n, c, s, ans, a[N], b[N], mx[N], mx2[N];
int main()
{
	ll i, j;
	cin >> n >> c;
	for (i = 0; i < n; i++) {
		scanf ("%lld %lld", &a[i], &b[i]);
	}
	for (i = n - 1; i >= 0; i--) {
		s += b[i];
		mx[i] = max(mx[i + 1], s - (c - a[i]));
		mx2[i] = max(mx2[i + 1], s - (c - a[i]) * 2);
	}
	ans = max(mx[0], mx2[0]);
	s = 0;
	for (i = 0; i < n; i++) {
		s += b[i];
		ans = max(ans, s - a[i] * 2 + mx[i + 1]);
		ans = max(ans, s - a[i] + mx2[i + 1]);
	}
	cout <<ans;
    return 0;
}
