#include <bits/stdc++.h>
using namespace std;
int main() {
  long n, c, x[100007], v[100007], a[100007], b[100007], d[100007], e[100007],
      f[100007], g[100007], al, ans;
  cin >> n >> c;
  ans = 0;
  for (long long i = 0; i < n; i++) {
    cin >> x[i] >> v[i];
  }
  for (long long i = 0; i < n; i++) {
    al += v[i];
  }
  a[0] = v[0] - 2 * x[0];
  b[0] = v[0] - x[0];
  for (long long i = 0; i < n; i++) {
    if (i != 0) {
      a[i] = a[i - 1] + v[i] + 2 * x[i - 1];
      b[i] = a[i] - x[i];
      a[i] -= 2 * x[i];
    }
  }
  d[0] = al - 2 * c + 2 * x[0];
  e[0] = al - c + x[0];
  for (long long i = 0; i < n; i++) {
    if (i != 0) {
      d[i] = d[i - 1] - v[i - 1] + 2 * c - 2 * x[i - 1];
      e[i] = d[i];
      d[i] -= 2 * c;
      d[i] += 2 * x[i];
      e[i] -= c;
      e[i] += x[i];
    }
    f[0] = a[0];
    for (long long i = 1; i < n - 1; i++) {
      if (f[i - 1] < a[i])
        f[i] = a[i];
      else
        f[i] = f[i - 1];
    }
    g[0] = b[0];
    for (long long i = 1; i < n - 1; i++) {
      if (g[i - 1] < b[i])
        g[i] = b[i];
      else
        g[i] = g[i - 1];
    }
  }
  for (long long i = 0; i < n - 1; i++) {
    if (f[i - 1] + e[i] < g[i - 1] + d[i] && ans < g[i - 1] + d[i])
      ans = g[i - 1] + d[i];
    else if (ans < f[i - 1] + e[i])
      ans = f[i - 1] + e[i];
  }
  for (long long i = 0; i < n; i++) {
    if (ans < b[i]) ans = b[i];
    if (ans < e[i]) ans = e[i];
  }
  printf("%ld", ans);
}
