#include <bits/stdc++.h>
using namespace std;
long long n, c, sum[100010], s1[100010], s2[100010], now1, now2, k1, k2, c1, c2,
    ans1, ans2, ans;
struct ab {
  long long x, v;
} a[100010], b[100010];
int main() {
  scanf("%lld%lld", &n, &c);
  for (int i = 1; i <= n; ++i) {
    scanf("%lld%lld", &a[i].x, &a[i].v);
    b[n - i + 1].x = c - a[i].x;
    b[n - i + 1].v = a[i].v;
  }
  for (int i = 1; i <= n; ++i) {
    sum[i] = sum[i - 1] + a[i].v;
    s1[i] = sum[i] - a[i].x;
    if (s1[i] > now1) {
      now1 = s1[i];
      k1 = i;
    }
  }
  for (int i = 1; i <= n; ++i) {
    sum[i] = sum[i - 1] + b[i].v;
    s2[i] = sum[i] - 2 * b[i].x;
    if (s2[i] > now2) {
      now2 = s2[i];
      k2 = i;
    }
  }
  if (k1 + k2 <= n)
    ans1 = now1 + now2;
  else {
    for (int i = 1; i < n; ++i)
      for (int j = i + 1; j <= n; ++j) ans1 = max(ans1, s1[i] + s2[j]);
  }
  now1 = 0;
  now2 = 0;
  for (int i = 1; i <= n; ++i) {
    sum[i] = sum[i - 1] + b[i].v;
    s1[i] = sum[i] - b[i].x;
    if (s1[i] > now1) {
      now1 = s1[i];
      k1 = i;
    }
  }
  for (int i = 1; i <= n; ++i) {
    sum[i] = sum[i - 1] + a[i].v;
    s2[i] = sum[i] - 2 * a[i].x;
    if (s2[i] > now2) {
      now2 = s2[i];
      k2 = i;
    }
  }
  if (k1 + k2 <= n)
    ans2 = now1 + now2;
  else {
    for (int i = 1; i < n; ++i)
      for (int j = i + 1; j <= n; ++j) ans2 = max(ans2, s1[i] + s2[j]);
  }
  ans = max(ans1, ans2);
  printf("%lld\n", ans);
  return 0;
}
