#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, c;
  cin >> n >> c;
  vector<long long int> x(n);
  vector<long long int> v(n);
  vector<long long int> x2(n);
  vector<long long int> vp(n, 0);
  vector<long long int> vq(n, 0);
  vector<long long int> vp2(n, 0);
  vector<long long int> vq2(n, 0);
  for (long long int i = 0; i < n; i++) {
    cin >> x[i] >> v[i];
    x2[i] = c - x[i];
  }
  long long int ans = 0;
  for (long long int i = 0; i < n; i++) {
    vp[i] = v[i];
    if (i > 0) {
      vp[i] = vp[i - 1] + v[i];
    }
  }
  for (long long int i = 0; i < n; i++) {
    vp[i] -= x[i];
  }
  for (long long int i = n - 1; i >= 0; i--) {
    vq[i] = v[i];
    if (i < n - 1) {
      vq[i] = vq[i + 1] + v[i];
    }
  }
  for (long long int i = 0; i < n; i++) {
    vq[i] -= x2[i];
  }
  vp2 = vp;
  vq2 = vq;
  for (long long int i = 0; i < n; i++) {
    vp2[i] = vp[i] - x[i];
    if (i > 0) {
      vp2[i] = max(vp2[i], vp2[i - 1]);
    }
  }
  for (long long int i = n - 1; i >= 0; i--) {
    vq2[i] = vq[i] - x2[i];
    if (i < n - 1) {
      vq2[i] = max(vq2[i], vq2[i + 1]);
    }
  }
  for (long long int i = 0; i < n; i++) {
    long long int ans2 = vp[i];
    if (i + 1 < n && vq2[i + 1] > 0) {
      ans2 += vq2[i + 1];
    }
    ans = max(ans, ans2);
    ans2 = vq[i];
    if (i - 1 > 0 && vp2[i - 1] > 0) {
      ans2 += vp2[i - 1];
    }
    ans = max(ans, ans2);
  }
  cout << ans << endl;
  return 0;
}
