#include <bits/stdc++.h>
using namespace std;
long long n, c, v[100000], x[100000], s[2][100000], d[2][100000], ss[2][100000],
    dd[2][100000];
long long xx(int i) {
  if (i == 0) return 0;
  if (i < 0) return c - x[n + i + 1];
  return x[i];
}
long long vv(int i) {
  if (i == 0) return 0;
  if (i < 0) return v[n + i + 1];
  return v[i];
}
int main() {
  cin >> n >> c;
  for (long long signed i = 1; i < n + 1; i++) {
    cin >> x[i] >> v[i];
  }
  for (long long signed i = 1; i < n + 1; i++) {
    s[0][i] = s[0][i - 1] + vv(i) - (xx(i) - xx(i - 1));
    d[0][i] = d[0][i - 1] + vv(-i) - (xx(-i) - xx(-i + 1));
    ss[0][i] = max(ss[0][i - 1], s[0][i]);
    dd[0][i] = max(dd[0][i - 1], d[0][i]);
    s[1][i] = s[1][i - 1] + vv(i) - 2 * (xx(i) - xx(i - 1));
    d[1][i] = d[1][i - 1] + vv(-i) - 2 * (xx(-i) - xx(-i + 1));
    ss[1][i] = max(ss[1][i - 1], s[1][i]);
    dd[1][i] = max(dd[1][i - 1], d[1][i]);
  }
  long long signed res = 0;
  for (long long signed i = 0; i < n + 1; i++) {
    res = max(res, max(ss[1][i] + dd[0][n - i], ss[0][i] + dd[1][n - i]));
  }
  cout << res << endl;
}
