#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
template <class T>
T &chmin(T &a, const T &b) {
  return a = min(a, b);
}
template <class T>
T &chmax(T &a, const T &b) {
  return a = max(a, b);
}
template <class T>
istream &operator>>(istream &is, vector<T> &v) {
  for (auto &i : v) is >> i;
  return is;
}
template <class T>
ostream &operator<<(ostream &os, vector<T> &v) {
  const string delimiter = "\n";
  for (int i = (int)(0); i < (int)(v.size()); i++) {
    os << v[i];
    if (i != v.size() - 1) os << delimiter;
  }
  return os;
}
int main() {
  cin.sync_with_stdio(false);
  cout << fixed << setprecision(10);
  long long n, c;
  cin >> n >> c;
  vector<long long> x(n), v(n);
  for (int i = (int)(0); i < (int)(n); i++) cin >> x[i] >> v[i];
  vector<long long> cs(n + 1), ccs(n + 1);
  for (int i = (int)(0); i < (int)(n); i++) {
    cs[i + 1] = cs[i] + v[i];
    ccs[i + 1] = ccs[i] + v[n - i - 1];
  }
  vector<long long> cw(n + 1), ccw(n + 1);
  for (int i = (int)(1); i < (int)(n + 1); i++) {
    cw[i] = cs[i] - x[i - 1];
    ccw[i] = ccs[i] - (c - x[n - i]);
  }
  long long ans = 0;
  long long mxcw = *max_element(cw.begin(), cw.end());
  long long mxccw = *max_element(ccw.begin(), ccw.end());
  chmax(ans, mxcw);
  chmax(ans, mxccw);
  long long tccw = ccw[0];
  for (int i = n; i >= 1; i--) {
    long long tmp = cw[i] - x[i - 1];
    chmax(ans, tmp + tccw);
    chmax(tccw, ccw[n - i]);
  }
  long long tcw = cw[0];
  for (int i = n; i >= 1; i--) {
    long long tmp = ccw[i] - (c - x[n - i]);
    chmax(ans, tmp + tcw);
    chmax(tcw, cw[n - i]);
  }
  cout << ans << endl;
  return 0;
}
