#include <bits/stdc++.h>
using namespace std;
long long power(long long b, long long e) {
  long long sol = 1;
  while (e > 0) {
    if (e & 1) {
      sol = sol * b;
    }
    e >>= 1;
    b *= b;
  }
  return sol;
}
long long x[100000];
long long v[100000];
long long pt[100000];
long long ptR[100000];
long long ptm[100000];
long long ptmR[100000];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  long long C;
  cin >> N >> C;
  for (int i = (0); i <= (N - 1); ++i) {
    cin >> x[i] >> v[i];
  }
  pt[0] = v[0];
  ptR[N - 1] = v[N - 1];
  for (int i = (1); i <= (N - 1); ++i) {
    pt[i] = pt[i - 1] + v[i];
    ptR[N - 1 - i] = ptR[N - i] + v[N - 1 - i];
  }
  ptm[0] = pt[0] - 2 * x[0];
  ptmR[N - 1] = ptR[N - 1] - 2 * (C - x[N - 1]);
  for (int i = (1); i <= (N - 1); ++i) {
    ptm[i] = max(ptm[i - 1], pt[i] - 2 * x[i]);
    ptmR[N - 1 - i] = max(ptmR[N - i], ptR[N - 1 - i] - (C - 2 * x[N - 1 - i]));
  }
  long long opt = max(pt[N - 1] - x[N - 1], ptR[0] - (C - x[0]));
  for (int i = (0); i <= (N - 1 - 1); ++i) {
    long long tmp =
        max(pt[i] - x[i] + ptmR[i + 1], ptR[i + 1] - (C - x[i + 1]) + ptm[i]);
    opt = max(opt, tmp);
  }
  if (opt < 0) opt = 0;
  cout << opt << endl;
}
