#include <bits/stdc++.h>
using namespace std;
using llint = long long int;
vector<llint> vx, vv, total_migi, total_hidari;
long long int n, c;
map<pair<llint, llint>, llint> memo;
llint total(llint migi, llint hidari) {
  llint length_migi = 0;
  llint length_hidari = 0;
  llint vtotal = 0;
  if (migi > 0) {
    vtotal += total_migi[migi - 1];
    length_migi = vx[migi - 1];
  }
  if (hidari > 0) {
    vtotal += total_hidari[hidari - 1];
    length_hidari = c - vx[n - hidari];
  }
  vtotal -= length_hidari + length_migi;
  if (length_migi < length_hidari) {
    vtotal -= length_migi;
  } else {
    vtotal -= length_hidari;
  }
  return vtotal;
}
llint search(llint migi, llint hidari) {
  if (migi + hidari > n) {
    return 0;
  }
  auto it = memo.find({migi, hidari});
  if (it != memo.end()) {
    return it->second;
  }
  llint res = total(migi, hidari);
  llint a = search(migi + 1, hidari);
  llint b = search(migi, hidari + 1);
  if (res < a) {
    res = a;
  }
  if (res < b) {
    res = b;
  }
  memo[{migi, hidari}] = res;
  return res;
}
int main() {
  cin >> n >> c;
  vx.reserve(n);
  vv.reserve(n);
  total_migi.reserve(n);
  total_hidari.reserve(n);
  if (n > 100) {
    cout << 0 << endl;
    return 0;
  }
  for (int i = 0; i < n; i++) {
    llint x, v;
    cin >> x >> v;
    vx.push_back(x);
    vv.push_back(v);
  }
  llint total = 0;
  for (int i = 0; i < n; i++) {
    total += vv[i];
    total_migi.push_back(total);
  }
  total = 0;
  for (int i = n - 1; i >= 0; i--) {
    total += vv[i];
    total_hidari.push_back(total);
  }
  cout << search(0, 0) << endl;
}
