#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void solve();
int main() { solve(); }
void solve() {
  ll n, c, x[100002], u[100002];
  scanf("%lld %lld", &n, &c);
  for (int i = 1; i <= n; i++) scanf("%lld %lld", x + i, u + i);
  x[0] = 0, u[0] = 0;
  u[n + 1] = c, x[n + 1] = 0;
  ll dp_r[100002], dp_l[100002], dp_rr[100002], dp_lr[100002];
  dp_r[0] = 0;
  for (int i = 1; i <= n; i++) dp_r[i] = dp_r[i - 1] + u[i];
  for (int i = 1; i <= n; i++) dp_r[i] = dp_r[i] - x[i];
  dp_l[n + 1] = 0;
  for (int i = n; 1 <= i; i--) dp_l[i] = dp_l[i + 1] + u[i];
  for (int i = n; 1 <= i; i--) dp_l[i] = dp_l[i] - (c - x[i]);
  dp_rr[0] = 0;
  for (int i = 1; i <= n; i++) dp_rr[i] = dp_r[i] - x[i];
  dp_lr[n + 1] = 0;
  for (int i = n; 1 <= i; i--) dp_lr[i] = dp_l[i] - (c - x[i]);
  ll maxv = 0;
  for (int r = 0; r <= n; r++)
    for (int l = r + 1; l <= (n + 1); l++)
      maxv = max(maxv, max(dp_rr[r] + dp_l[l], dp_r[r] + dp_lr[l]));
  printf("%lld\n", maxv);
}
