#include <bits/stdc++.h>
using namespace std;
const int maxn = 10000 + 10;
const int INF = int(1e9);
long long x[maxn], v[maxn];
long long dpr[maxn], dpl[maxn];
void init() {
  memset(x, 0, sizeof(x));
  memset(v, 0, sizeof(v));
  memset(dpr, 0, sizeof(dpr));
  memset(dpl, 0, sizeof(dpl));
}
int main() {
  int n;
  long long c, rsum = 0, lsum = 0, sum = 0, ans = 0;
  init();
  scanf("%d %lld", &n, &c);
  for (int i = 1; i <= n; i++) {
    scanf("%lld %lld", &x[i], &v[i]);
    sum += v[i];
  }
  for (int i = 2; i <= n; i++) {
    rsum += v[i - 1];
    dpr[i] = max(dpr[i - 1], rsum - x[i - 1] * 2);
  }
  for (int i = n - 1; i >= 1; i--) {
    lsum += v[i + 1];
    dpl[i] = max(dpl[i + 1], lsum - (c - x[i + 1]) * 2);
  }
  lsum = 0;
  rsum = 0;
  for (int i = 1; i <= n; i++) {
    rsum += v[i];
    ans = max(ans, rsum - x[i] + dpl[i]);
  }
  for (int i = n; i >= 1; i--) {
    lsum += v[i];
    ans = max(ans, lsum - (c - x[i]) + dpr[i]);
  }
  printf("%lld\n", ans);
  return 0;
}
