#include <bits/stdc++.h>
long long remin(long long a, long long b) {
  if (a < b)
    return a;
  else
    return b;
}
long long nri[100005];
long long dis[100005];
long long clkwise[100005], counter[100005];
int main() {
  int n, i;
  long long nrisum, out;
  long long temp;
  long long c;
  scanf("%d%lld", &n, &c);
  for (i = 1; i <= n; i++) {
    scanf("%lld%lld", &dis[i], &nri[i]);
  }
  long long ans;
  out = 0;
  nrisum = 0;
  ans = 0;
  for (i = 1; i <= n; i++) {
    nrisum = nrisum + nri[i];
    if (nrisum - dis[i] > ans) ans = nrisum - dis[i];
    clkwise[i] = ans;
  }
  nrisum = 0;
  if (ans > out) out = ans;
  ans = 0;
  for (i = n; i >= 1; i--) {
    nrisum = nrisum + nri[i];
    if (nrisum - (c - dis[i]) > ans) ans = nrisum - (c - dis[i]);
    counter[i] = ans;
  }
  if (ans > out) out = ans;
  for (i = 1; i <= n; i++) {
    if (clkwise[i] + counter[i + 1] - remin(dis[i], c - dis[i]) > out)
      out = clkwise[i] + counter[i + 1] - remin(dis[i], c - dis[i]);
  }
  for (i = 1; i <= n; i++) dis[i] = c - dis[i];
  for (i = 1; i <= n / 2; i++) {
    temp = dis[i];
    dis[i] = dis[n - i + 1];
    dis[n - i + 1] = temp;
  }
  nrisum = 0;
  ans = 0;
  for (i = 1; i <= n; i++) {
    nrisum = nrisum + nri[i];
    if (nrisum - dis[i] > ans) ans = nrisum - dis[i];
    clkwise[i] = ans;
  }
  nrisum = 0;
  if (ans > out) out = ans;
  ans = 0;
  for (i = n; i >= 1; i--) {
    nrisum = nrisum + nri[i];
    if (nrisum - (c - dis[i]) > ans) ans = nrisum - (c - dis[i]);
    counter[i] = ans;
  }
  if (ans > out) out = ans;
  for (i = 1; i <= n; i++) {
    if (clkwise[i] + counter[i + 1] - remin(dis[i], c - dis[i]) > out)
      out = clkwise[i] + counter[i + 1] - remin(dis[i], c - dis[i]);
  }
  printf("%lld\n", out);
  return 0;
}
