#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, c;
  cin >> n >> c;
  vector<long long> x(n), v(n);
  vector<long long> cv(n, 0), anticv(n, 0);
  for (int i = 0; i < n; i++) {
    cin >> x[i] >> v[i];
  }
  cv[0] = v[0];
  anticv[0] = v[n - 1];
  for (int i = 1; i < n; i++) {
    cv[i] = cv[i - 1] + v[i];
    anticv[i] = anticv[i - 1] + v[n - 1 - i];
  }
  for (int i = 0; i < n; i++) {
    cv[i] -= x[i];
    anticv[i] -= c - x[n - 1 - i];
  }
  long long cv_idx = -1, cv_max = 0;
  long long acv_idx = -1, acv_max = 0;
  long long cv_idx_h = -1, cv_max_h = 0;
  long long acv_idx_h = -1, acv_max_h = 0;
  for (int i = 0; i < n; i++) {
    if (cv_max < cv[i]) {
      cv_max = cv[i];
      cv_idx = i;
    }
    if (cv_max_h < cv[i] && x[i] <= c / 2) {
      cv_max_h = cv[i];
      cv_idx_h = i;
    }
    if (acv_max < anticv[i]) {
      acv_max = anticv[i];
      acv_idx = i;
    }
    if (acv_max_h < anticv[i] && c - x[n - 1 - i] <= c / 2) {
      acv_max_h = anticv[i];
      acv_idx_h = i;
    }
  }
  long long ans = max(max(max(cv_max, acv_max), cv_max_h), acv_max_h);
  if (cv_idx == -1 && acv_idx == -1) {
    cout << "0" << endl;
    return 0;
  }
  long long t;
  for (int i = 0; i < n - cv_idx - 1; i++) {
    t = anticv[i] - (c - x[n - 1 - i]) + cv_max;
    ans = max(ans, t);
  }
  for (int i = 0; i < n - cv_idx_h - 1; i++) {
    t = anticv[i] - (c - x[n - 1 - i]) + cv_max_h;
    ans = max(ans, t);
  }
  for (int i = 0; i < n - acv_idx - 1; i++) {
    t = cv[i] - x[i] + acv_max;
    ans = max(ans, t);
  }
  for (int i = 0; i < n - acv_idx_h - 1; i++) {
    t = cv[i] - x[i] + acv_max_h;
    ans = max(ans, t);
  }
  cout << ans << endl;
  return 0;
}
