#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
long long n, C, x[N], v[N], pv[N], sv[N];
priority_queue<pair<long long, long long> > q, q2;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> C;
  for (int i = 1; i <= n; i++) cin >> x[i] >> v[i], pv[i] = pv[i - 1] + v[i];
  long long val = 0;
  for (int i = n; i >= 1; i--) {
    val += v[i], sv[i] = val;
    q.push(pair<long long, long long>(val - (C - x[i]), n - i + 1));
  }
  long long res = 0, p = 1, mx = 0;
  for (int i = 0; i <= n; i++) {
    long long c1 = 2ll * x[i];
    if (i == 0) c1 = 0;
    while (!q.empty() &&
           (q.top().second > n - i || C - x[n - q.top().second + 1] <= x[i]))
      q.pop();
    if (!q.empty()) res = max(res, pv[i] - c1 + max(0ll, q.top().first));
    while (p <= n - i && C - x[n - p + 1] <= x[i])
      q2.push(pair<long long, long long>(
          sv[n - p + 1] - 2ll * (C - x[n - p + 1]), p)),
          p++;
    while (!q2.empty() && (q.top().second > n - i)) q2.pop();
    if (!q2.empty()) res = max(res, pv[i] - x[i] + max(0ll, q2.top().first));
  }
  cout << res << '\n';
  return 0;
}
