#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
long long pref[N], suff[N];
long long suffMx[N][2];
long long x[N], w[N];
int main() {
  int n;
  long long c;
  scanf("%d%I64d", &n, &c);
  for (int i = 0; i < n; ++i) scanf("%I64d%I64d", &x[i], &w[i]);
  pref[0] = suff[0] = 0;
  for (int i = 1; i <= n; ++i) {
    pref[i] = pref[i - 1] + w[i - 1];
    suff[i] = suff[i - 1] + w[n - i];
  }
  for (int i = 1; i <= n; ++i) {
    pref[i] -= x[i - 1];
    suff[i] -= (c - x[n - i]);
  }
  suffMx[0][0] = suffMx[0][1] = 0;
  for (int i = 1; i <= n; ++i) {
    suffMx[i][0] = max(suffMx[i - 1][0], suff[i]);
    suffMx[i][1] = max(suffMx[i - 1][1], suff[i] - (c - x[n - i]));
  }
  long long ans = max(0ll, pref[n] - min(c - x[0], x[n - 1]));
  for (int i = 0, j; i < n; ++i) {
    auto it = lower_bound(x, x + n, c - x[i]);
    j = it - x;
    if (j <= i) j = i + 1;
    ans = max(ans, max(suffMx[n - j][1] + pref[i + 1],
                       pref[i + 1] - x[i] + suffMx[max(n - i - 1, n - j)][0]));
  }
  cout << ans;
}
