#include <bits/stdc++.h>
long long int val[100000][2];
int main(void) {
  long long int n, c, maxv = 0, remv = 0, x, v, t, max = 0, i;
  scanf("%lld %lld", &n, &c);
  scanf("%lld %lld", &val[0][0], &val[0][1]);
  for (i = 1; i < n; i++) {
    scanf("%lld %lld", &x, &v);
    val[i][0] = x;
    val[i][1] = val[i - 1][1] + v;
  }
  if (val[n - 1][1] - val[n - 1][0] > 0) max = val[n - 1][1] - val[n - 1][0];
  for (i = 0; i < n - 1; i++) {
    t = val[n - 1][1] - val[n - 2 - i][1] - (c - val[n - 1 - i][0]);
    if (t > maxv) maxv = t;
    t -= c - val[n - 1 - i][0];
    if (t > remv) remv = t;
    t = remv + val[n - 2 - i][1] - val[n - 2 - i][0];
    if (t > max) max = t;
    t = maxv + val[n - 2 - i][1] - val[n - 2 - i][0] * 2;
    if (t > max) max = t;
  }
  t = val[n - 1][1] - (c - val[0][0]);
  if (t > max) max = t;
  printf("%lld\n", max);
  return 0;
}
