#include <bits/stdc++.h>
using namespace std;
long long n, c, x[100100] = {0}, v[100100] = {0};
long long res = 0;
long long sx[100100] = {0}, sv[100100] = {0}, a[100100] = {0}, b[100100] = {0},
          rx[100100] = {0};
signed main() {
  cin >> n >> c;
  for (int i = 0; i < n; ++i) {
    cin >> x[i] >> v[i];
    sv[i + 1] = sv[i] + v[i];
    rx[i] = c - x[i];
  }
  a[n - 1] = max(0LL, v[n - 1] - rx[n - 1]),
        b[n - 1] = max(0LL, v[n - 1] - 2 * rx[n - 1]);
  for (int i = n - 2; i >= 0; --i) {
    a[i] = max(a[i + 1], sv[n] - sv[i] - rx[i]);
    b[i] = max(b[i + 1], sv[n] - sv[i] - 2 * rx[i]);
  }
  for (int i = 0; i <= n; ++i) {
    long long t = sv[i];
    if (i == 0) {
      t += a[0];
      res = max(res, t);
    } else {
      t -= x[i - 1];
      int k = lower_bound(rx, rx + n, x[i - 1], greater<long long>()) - rx;
      if (k < n) {
        if (i < k)
          t = max(t, t + b[k]);
        else if (i < n)
          t = max(t, t + b[i + 1]);
      }
      if (i < n) t = max(t, t + a[i + 1] - x[i - 1]);
      res = max(res, t);
    }
  }
  cout << res << endl;
  return 0;
}
