#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const long long int LINF = 1 << 30;
template <typename T>
void printv(vector<T> const& s) {
  for (int i = (0); i < (((int)(s).size())); i++) {
    cout << s[i] << " ";
  }
  cout << endl;
}
int main() {
  cin.tie(0);
  cout << setprecision(10);
  long long int n, c;
  cin >> n >> c;
  vector<long long int> x(n), v(n);
  for (int i = (0); i < (n); i++) {
    cin >> x[i] >> v[i];
  }
  vector<long long int> sr(n);
  sr[0] = v[0] - x[0];
  for (int i = (1); i < (n); i++) {
    sr[i] = sr[i - 1] + v[i] - (x[i] - x[i - 1]);
  }
  vector<long long int> sl(n);
  sl[0] = v[n - 1] - (c - x[n - 1]);
  for (int i = (1); i >= (n); i--) {
    sl[i] = sl[i - 1] + v[n - i - 1] - (x[n - i - 1] - x[n - i - 2]);
  }
  vector<long long int> ma1r(n);
  ma1r[0] = sr[0];
  for (int i = (1); i < (n); i++) {
    ma1r[i] = max(ma1r[i - 1], sr[i]);
  }
  vector<long long int> ma1l(n);
  ma1l[0] = sl[0];
  for (int i = (1); i < (n); i++) {
    ma1l[i] = max(ma1l[i - 1], sl[i]);
  }
  vector<long long int> ma2r(n);
  ma2r[0] = sr[0] - x[0];
  for (int i = (1); i < (n); i++) {
    ma2r[i] = max(ma2r[i - 1], sr[i] - x[i]);
  }
  vector<long long int> ma2l(n);
  ma2l[0] = sl[0] - (c - x[n - 1]);
  for (int i = (1); i < (n); i++) {
    ma2l[i] = max(ma2l[i - 1], sl[i] - (c - x[n - i - 1]));
  }
  long long int ans = max(0ll, max(ma1r[n - 1], ma1l[n - 1]));
  for (int i = (0); i < (n - 1); i++) {
    ans = max(ans, max(max(0ll, ma1r[i]) + max(0ll, ma2l[n - 2 - i]),
                       max(0ll, ma2r[i]) + max(0ll, ma1l[n - 2 - i])));
  }
  cout << ans << endl;
}
