#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 ptRev[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];
  }
  long long taken = 0;
  for (int i = (0); i <= (N - 1); ++i) {
    taken += v[i];
    pt[i] = taken - x[i];
  }
  taken = 0;
  for (int i = (N - 1); i >= (0); --i) {
    taken += v[i];
    ptRev[N - 1 - i] = taken - (C - x[i]);
  }
  int maxP = 0, maxPr = 0;
  for (int i = (0); i <= (N - 1); ++i) {
    maxP = (pt[i] > pt[maxP]) ? i : maxP;
    maxPr = (ptRev[i] > ptRev[maxPr]) ? i : maxPr;
  }
  long long opt = max(pt[maxP], ptRev[maxPr]);
  opt = (opt > 0) ? opt : 0;
  for (int i = (0); i <= (N - 1 - 1); ++i) {
    if (maxPr + i < N - 1) {
      opt = max(opt, ptRev[maxPr] + pt[i] - x[i]);
    }
    if (maxP + i < N - 1) {
      opt = max(opt, pt[maxP] + ptRev[i] - (C - x[N - 1 - i]));
    }
  }
  cout << opt << endl;
}
