#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int N = n + 2;
  long long c;
  cin >> c;
  long long x[N], v[N];
  long long lx[N], lc[N], rx[N], rc[N];
  for (int i = (1); i < (N - 1); ++i) cin >> x[i] >> v[i];
  x[0] = v[0] = lx[0] = lc[0] = rx[0] = rc[0] = 0;
  x[N - 1] = v[N - 1] = lx[N - 1] = lc[N - 1] = rx[N - 1] = rc[N - 1] = 0;
  long long ans = 0;
  for (int i = (1); i < (N - 1); ++i) {
    lx[i] = x[i];
    lc[i] = lc[i - 1] + v[i];
    ans = max(ans, lc[i] - lx[i]);
  }
  for (int i = N - 2; i > 0; i--) {
    rx[i] = c - x[i];
    rc[i] = rc[i + 1] + v[i];
    ans = max(ans, rc[i] - rx[i]);
  }
  for (int i = (1); i < (N - 1); ++i) {
    for (int j = N - 2; j > i; j--) {
      long long l = lc[i] + rc[j] - 2 * lx[i] - rx[j];
      long long r = lc[i] + rc[j] - lx[i] - 2 * rx[j];
      ans = max(ans, l);
      ans = max(ans, r);
    }
  }
  cout << ans << endl;
  return 0;
}
