#include <bits/stdc++.h>
using namespace std;
const int maxn = 100010;
long long x[maxn], v[maxn], sum_v[maxn];
int main() {
  int n;
  long long c;
  scanf("%d%lld", &n, &c);
  for (int i = 1; i <= n; i++) {
    scanf("%lld%lld", x + i, v + i);
    sum_v[i] = sum_v[i - 1] + v[i];
  }
  int idx = 0;
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    ans = max(ans, sum_v[i] - x[i]);
    idx = max(idx, i + 1);
    while (idx + 1 <= n &&
           sum_v[i] + sum_v[n] - sum_v[idx - 1] - (x[i] + x[i] + c - x[idx]) <=
               sum_v[i] + sum_v[n] - sum_v[idx] -
                   (x[i] + x[i] + c - x[idx + 1]))
      idx++;
    if (idx <= n)
      ans = max(ans, sum_v[i] + sum_v[n] - sum_v[idx - 1] -
                         (x[i] + x[i] + c - x[idx]));
  }
  reverse(x + 1, x + 1 + n);
  reverse(v + 1, v + 1 + n);
  for (int i = 1; i <= n; i++) {
    x[i] = c - x[i];
    sum_v[i] = sum_v[i - 1] + v[i];
  }
  idx = 0;
  for (int i = 1; i <= n; i++) {
    ans = max(ans, sum_v[i] - x[i]);
    idx = max(idx, i + 1);
    while (idx + 1 <= n &&
           sum_v[i] + sum_v[n] - sum_v[idx - 1] - (x[i] + x[i] + c - x[idx]) <=
               sum_v[i] + sum_v[n] - sum_v[idx] -
                   (x[i] + x[i] + c - x[idx + 1]))
      idx++;
    if (idx <= n)
      ans = max(ans, sum_v[i] + sum_v[n] - sum_v[idx - 1] -
                         (x[i] + x[i] + c - x[idx]));
  }
  printf("%lld\n", ans);
  return 0;
}
