#include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 62;
const int inf = 1 << 29;
int main() {
  long long N, c;
  cin >> N >> c;
  vector<long long> x(N + 2), v(N + 2);
  for (int i = (0); i < (N); ++i) cin >> x[i + 1] >> v[i + 1];
  x[0] = 0;
  v[0] = 0;
  x[N + 1] = c;
  v[N + 1] = 0;
  long long ans = 0, st = 0;
  long long lmax = 0, rmax = 0;
  for (int i = (1); i < (N + 1); ++i) {
    st += v[i];
    st -= x[i] - x[i - 1];
    ans = max(st, ans);
    if (x[i] * 2 <= c) rmax = max(rmax, st);
  }
  st = 0;
  x[0] = 0;
  for (int i = (0); i < (N); ++i) {
    st += v[N - i];
    st -= (c - x[N - i]) - (c - x[N - (i - 1)]);
    ans = max(st, ans);
    if ((c - x[N - i]) * 2 <= c) lmax = max(lmax, st);
  }
  st = 0;
  for (int i = 1; i <= N && x[i] * 2 < c; i++) {
    st += v[i];
    st -= x[i] - x[i - 1];
    ans = max(st - x[i] + lmax, ans);
  }
  st = 0;
  for (int i = 0; i < N && (c - x[N - i]) * 2 < c; i++) {
    st += v[N - i];
    st -= (c - x[N - i]) - (c - x[N - (i - 1)]);
    ans = max(st - (c - x[N - i]) + rmax, ans);
  }
  cout << ans << endl;
  return 0;
}
