#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, c;
  cin >> n >> c;
  long long v[n];
  long long x[n];
  long long ans = 0;
  long long ri[n + 1];
  long long rit[n + 1];
  long long op[n + 1];
  long long opt[n + 1];
  ri[0] = 0;
  rit[0] = 0;
  op[0] = 0;
  opt[0] = 0;
  long long risum = 0;
  long long ritsum = 0;
  for (long long i = 0; i < n; i++) {
    cin >> x[i] >> v[i];
    if (i)
      risum += v[i] - (x[i] - x[i - 1]),
          ri[i + 1] = max(ri[i], risum), ritsum += v[i] - (x[i] - x[i - 1]) * 2,
                 rit[i + 1] = max(rit[i], ritsum);
    else
      risum = ri[i] + v[i] - x[i], ri[i + 1] = max(ri[i], risum),
      ritsum = rit[i] + v[i] - x[i] * 2, rit[i + 1] = max(rit[i], ritsum);
  }
  long long opsum = 0;
  long long optsum = 0;
  for (long long i = 0; i < n; i++) {
    if (i)
      opsum += v[n - i - 1] - (x[n - i] - x[n - i - 1]),
          op[i + 1] = max(op[i], opsum),
                 optsum += v[n - i - 1] - (x[n - i] - x[n - i - 1]) * 2,
                 opt[i + 1] = max(opt[i], optsum);
    else
      opsum += op[i] + v[n - i - 1] - (c - x[n - i - 1]),
          op[i + 1] = max(op[i], opsum),
                 optsum += opt[i] + v[n - i - 1] - (c - x[n - i - 1]) * 2,
                 opt[i + 1] = max(opt[i], optsum);
  }
  for (long long i = 1; i <= n; i++) {
    ans = max(ans, max(ri[i] + opt[n - i], rit[i] + op[n - i]));
  }
  cout << ans << endl;
  return 0;
}
