#include <bits/stdc++.h>
using namespace std;
const long long INF = 10000000000000000;
int main() {
  long long n, c;
  cin >> n >> c;
  pair<long long, long long> xv[100000];
  for (int i = 0, i_len = (n); i < i_len; ++i)
    cin >> xv[i].first >> xv[i].second;
  sort(xv, xv + n);
  long long lmax[10000];
  lmax[0] = -INF;
  long long rmax[10000];
  rmax[0] = -INF;
  {
    long long t = 0;
    long long prevx = c;
    for (int i = n - 1; i >= 0; i--) {
      t -= prevx - xv[i].first;
      t += xv[i].second;
      lmax[n - i] = max(lmax[n - i - 1], t);
      prevx = xv[i].first;
    }
    t = prevx = 0;
    for (int i = 0; i < n; i++) {
      t -= xv[i].first - prevx;
      t += xv[i].second;
      rmax[i + 1] = max(rmax[i], t);
      prevx = xv[i].first;
    }
  }
  lmax[0] = 0;
  rmax[0] = 0;
  long long ans = max({lmax[n], rmax[n], (long long)0});
  long long nv = 0;
  long long prevx = 0;
  for (int i = 0, i_len = (n); i < i_len; ++i) {
    nv -= xv[i].first - prevx;
    nv += xv[i].second;
    prevx = xv[i].first;
    ans = max({ans, nv - prevx + lmax[n - i - 1], nv});
  }
  nv = 0;
  prevx = c;
  for (int i = 0, i_len = (n); i < i_len; ++i) {
    nv -= prevx - xv[n - i - 1].first;
    nv += xv[n - i - 1].second;
    prevx = xv[n - i - 1].first;
    ans = max({ans, nv - (c - prevx) + rmax[n - i - 1], nv});
  }
  cout << ans << endl;
}
