#include <bits/stdc++.h>
using namespace std;
template <typename T>
ostream& operator<<(ostream& out, const vector<T>& v) {
  out << "[";
  for (auto& e : v) out << e << " ";
  out << "]";
  return out;
}
int main() {
  int n;
  long long c;
  cin >> n >> c;
  vector<long long> x(n), v(n);
  for (int i = 0; i < n; i++) {
    cin >> x[i] >> v[i];
  }
  long long ans = 0;
  vector<long long> ps(n + 1), ms(n + 1);
  ps[0] = 0;
  ms[0] = 0;
  for (int i = 0; i < n; i++) {
    ps[i + 1] = ps[i] + v[i];
    ms[i + 1] = ms[i] + v[n - i - 1];
  }
  for (int i = 0; i < n; i++) {
    ps[i + 1] -= x[i];
    ms[i + 1] -= (c - x[n - i - 1]);
  }
  vector<long long> max_ps(n + 1), max_ms(n + 1);
  max_ps[0] = 0;
  max_ms[0] = 0;
  for (int i = 0; i < n; i++) {
    max_ps[i + 1] = max(ps[i], max_ps[i]);
    max_ms[i + 1] = max(ms[i], max_ms[i]);
  }
  for (int i = 0; i < n + 1; i++) {
    long long xp = i == 0 ? 0 : c - x[n - i];
    long long tp = ms[i] - xp + max_ps[n - i];
    if (tp > ans) ans = tp;
    long long xm = i == 0 ? 0 : x[i - 1];
    long long tm = ps[i] - xm + max_ms[n - i];
    if (tm > ans) ans = tm;
  }
  cout << ans << endl;
  return 0;
}
