#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, c;
  cin >> n >> c;
  vector<pair<long long, long long> > vp1(n), vp2(n);
  for (int i = 0; i < n; i++) {
    long long d, v;
    cin >> d >> v;
    vp1[i] = {d, v};
    vp2[n - i - 1] = {c - d, v};
  }
  long long ans = 0;
  vector<pair<long long, long long> > va(n), vb(n);
  long long ttl = 0;
  long long mxttl = 0, mxdis = 0;
  for (int i = 0; i < n; i++) {
    ttl += vp1[i].second;
    if (ttl - vp1[i].first > mxttl) {
      mxttl = ttl;
      mxdis = vp1[i].first;
    }
    va[i].first = mxttl;
    va[i].second = mxdis;
  }
  ttl = 0;
  mxttl = 0, mxdis = 0;
  for (int i = 0; i < n; i++) {
    ttl += vp2[i].second;
    if (ttl - vp2[i].first > mxttl) {
      mxttl = ttl;
      mxdis = vp2[i].first;
    }
    vb[i].first = mxttl;
    vb[i].second = mxdis;
  }
  ans = max(ans, vb[n - 1].first - vb[n - 1].second);
  ans = max(ans, va[n - 1].first - va[n - 1].second);
  for (int i = 0; i < n - 1; i++) {
    ans = max(ans, va[i].first - va[i].second + vb[n - i - 2].first -
                       vb[n - i - 2].second -
                       min(vb[n - i - 2].second, va[i].second));
  }
  cout << ans << '\n';
  return 0;
}
