#include <bits/stdc++.h>
const double EXP = 1e-10;
using namespace std;
long long n, c;
long long x[10007];
long long v[10007];
long long maxs, maxn, cnts, cntn, ans, t;
int main() {
  scanf("%lld%lld", &n, &c);
  for (long long i = 1; i <= n; i++) {
    scanf("%lld%lld", x + i, v + i);
  }
  for (int i = 1; i <= n; i++) {
    t += v[i];
    if (t - x[i] > maxs) {
      maxs = t - x[i];
      cnts = i;
    }
  }
  t -= x[cnts];
  for (int i = n; i > cnts; i--) {
    t += v[i];
    if (t - 2 * (c - x[i]) > maxs) {
      maxs = t - 2 * (c - x[i]);
    }
  }
  ans = max(maxs, ans);
  t = 0;
  for (int i = n; i >= 1; i--) {
    t += v[i];
    if (t - (c - x[i]) > maxn) {
      maxn = t - (c - x[i]);
      cntn = i;
    }
  }
  t -= (c - x[cntn]);
  for (int i = 1; i < cntn; i++) {
    t += v[i];
    if (t - 2 * x[i] > maxn) {
      maxn = t - 2 * x[i];
    }
  }
  ans = max(maxn, ans);
  printf("%lld\n", ans);
  return 0;
}
