#include <bits/stdc++.h>
using namespace std;
using vint = vector<int>;
using ll = long long;
using vll = vector<ll>;
template <class T>
void chmin(T& a, const T& b) {
  a = min(a, b);
}
template <class T>
void chmax(T& a, const T& b) {
  a = max(a, b);
}
void yes() {
  cout << "Yes" << endl;
  exit(0);
}
void no() {
  cout << "No" << endl;
  exit(0);
}
int main() {
  int n;
  ll c;
  cin >> n >> c;
  vll x(n), v(n);
  for (int i = (0); i < (n); ++i) {
    cin >> x[i] >> v[i];
  }
  vll imosU(n, 0), imosD(n, 0);
  imosU[0] = v[0];
  imosD[0] = v[n - 1];
  for (int i = (0); i < (n - 1); ++i) {
    imosU[i + 1] += imosU[i] + v[i + 1];
    imosD[i + 1] += imosD[i] + v[n - i - 2];
  }
  ll ans = 0;
  for (int i = (0); i < (n); ++i) {
    chmax(ans, imosU[i] - x[i]);
    chmax(ans, imosD[i] - (c - x[n - i - 1]));
  }
  for (int i = (0); i < (n); ++i) {
    for (int j = (0); j < (n - i - 1); ++j) {
      chmax(ans, (imosU[i] - x[i]) - x[i] + (imosD[j] - (c - x[n - j - 1])));
      chmax(ans, (imosD[i] - (c - x[n - i - 1])) - (c - x[n - i - 1]) +
                     (imosU[j] - x[j]));
    }
  }
  cout << ans << endl;
  return 0;
}
