#include <bits/stdc++.h>
using namespace std;
int main() {
  int64_t N, C;
  vector<int64_t> X(100010, 0), revX(100010, 0), V(100010, 0), revV(100010, 0);
  cin >> N >> C;
  for (int i = 1; i <= (int)(N); i++) {
    cin >> X[i] >> V[i];
    revX[N - i + 1] = C - X[i];
    revV[N - i + 1] = V[i];
  }
  vector<int64_t> CW(100010, 0), antiCW(100010, 0);
  vector<int> antiCW_id(100010, 0);
  for (int i = 1; i <= (int)(N); i++) {
    CW[i] = CW[i - 1] + V[i] - (X[i] - X[i - 1]);
    antiCW[i] = antiCW[i - 1] + revV[i] - (revX[i] - revX[i - 1]);
    if (antiCW[i] > antiCW[i - 1])
      antiCW_id[i] = i;
    else
      antiCW_id[i] = antiCW_id[i - 1];
  }
  int64_t ans = 0;
  for (int i = 0; i < (int)(N + 1); i++) {
    int64_t R = CW[i];
    int64_t L = antiCW[antiCW_id[N - i]];
    int64_t D = min(X[i], revX[antiCW_id[N - i]]);
    if (L == 0 || R == 0) D = 0;
    ans = max(ans, R + L - D);
  }
  cout << ans << endl;
}
