#include <bits/stdc++.h>
using namespace std;
const int nmax = 1e9 + 7;
const long long INF = 1e18;
const double PI = 2 * asin(1);
int main() {
  int N;
  long long C;
  cin >> N >> C;
  vector<long long> X(N + 2), V(N + 2);
  for (int i = 1; i <= N; i++) {
    cin >> X[i] >> V[i];
  }
  X[N + 1] = C;
  vector<long long> sumV(N + 2), RsumV(N + 2);
  for (int i = 1; i < N + 2; i++) {
    sumV[i] = sumV[i - 1] + V[i];
  }
  for (int i = N + 1; i >= 0; i--) {
    RsumV[i] = RsumV[i + 1] + V[i];
  }
  long long ans = 0;
  for (int i = 0; i < N + 2; i++) {
    ans = max(ans, sumV[i] - X[i]);
  }
  for (int i = N + 1; i >= 0; i--) {
    ans = max(ans, RsumV[i] - (C - X[i]));
  }
  vector<long long> L1(N + 2), R1(N + 2);
  for (int i = 0; i < N + 2; i++) {
    L1[i] = sumV[i] - 2 * X[i];
  }
  for (int i = N + 1; i >= 0; i--) {
    R1[i] = RsumV[i] - (C - X[i]);
    if (i < N + 1) {
      R1[i] = max(R1[i], R1[i + 1]);
    }
  }
  for (int i = 0; i < N + 1; i++) {
    ans = max(ans, L1[i] + R1[i + 1]);
  }
  vector<long long> L2(N + 2), R2(N + 2);
  for (int i = N + 1; i >= 0; i--) {
    R2[i] = RsumV[i] - 2 * (C - X[i]);
  }
  for (int i = 0; i < N + 2; i++) {
    L2[i] = sumV[i] - X[i];
    if (i > 0) {
      L2[i] = max(L2[i - 1], L2[i]);
    }
  }
  for (int i = N + 1; i > 0; i--) {
    ans = max(ans, L2[i - 1] + R2[i]);
  }
  cout << ans << endl;
  return 0;
}
