#include <bits/stdc++.h>
using namespace std;
static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const long long INF = 1023456789;
long long n, c;
long long x[100000], v[100000];
long long a[200001], b[200001];
long long off = 100000;
int main(int argc, char **argv) {
  cin >> n >> c;
  for (int i = 0; i < n; ++i) cin >> x[i] >> v[i];
  long long m = 0, t = 0;
  for (int i = 0; i < n; ++i) {
    t += v[i] - x[i];
    if (i != 0) t += x[i - 1];
    m = max(m, t);
    a[off + 1 + i] = m;
  }
  m = t = 0;
  for (int i = 0; i < n; ++i) {
    t += v[n - 1 - i] - (c - x[n - 1 - i]);
    if (i != 0) t += c - x[n - i];
    m = max(m, t);
    b[off + 1 + i] = m;
  }
  m = t = 0;
  for (int i = 0; i < n; ++i) {
    t += v[n - 1 - i] - (c - x[n - 1 - i]) * 2;
    if (i != 0) t += c - x[n - i] * 2;
    m = max(m, t);
    a[off - 1 - i] = m;
  }
  m = t = 0;
  for (int i = 0; i < n; ++i) {
    t += v[i] - x[i] * 2;
    if (i != 0) t += x[i - 1] * 2;
    m = max(m, t);
    b[off - 1 - i] = m;
  }
  long long res = 0;
  for (int i = 0; i < n + 1; ++i) res = max(res, a[off - n + i] + a[off + i]);
  for (int i = 0; i < n + 1; ++i) res = max(res, b[off - n + i] + b[off + i]);
  cout << res << endl;
  return 0;
}
