#include <bits/stdc++.h>
using namespace std;
struct node {
  long long num;
  int id;
} g[100100];
long long c, last, ans, now;
long long f[100100], x[100100], v[100100];
int n;
bool cmp(node x, node y) {
  if (x.num == y.num) return x.id < y.id;
  return x.num > y.num;
}
int main() {
  scanf("%d%lld", &n, &c);
  for (int i = 1; i <= n; i++) scanf("%lld%lld", &x[i], &v[i]);
  x[n + 1] = c;
  for (int i = n; i; i--)
    g[i].num = g[i + 1].num + v[i] - (x[i + 1] - x[i]), g[i].id = i;
  sort(g + 1, g + n + 1, cmp);
  int cur = 1;
  ans = max(ans, g[1].num);
  for (int i = 1; i <= n; i++) {
    while (g[cur].id <= i) cur++;
    now += v[i] - 2 * (x[i] - last);
    last = x[i];
    ans = max(ans, now + g[cur].num);
  }
  for (int i = 1; i <= n; i++)
    g[i].num = g[i - 1].num + v[i] - (x[i] - x[i - 1]), g[i].id = i;
  sort(g + 1, g + n + 1, cmp);
  cur = 1;
  now = 0;
  ans = max(ans, g[1].num);
  for (int i = n; i; i--) {
    while (g[cur].id >= i) cur++;
    now += v[i] - 2 * (x[i + 1] - x[i]);
    ans = max(ans, now + g[cur].num);
  }
  printf("%lld\n", ans);
  return 0;
}
