#include <bits/stdc++.h>
using namespace std;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
void solve(long long N, long long C, std::vector<long long> x,
           std::vector<long long> v) {
  vector<long long> accLeft(N);
  vector<long long> accRight(N);
  vector<long long> accLeftBack(N);
  vector<long long> accRightBack(N);
  accLeft[0] = v[0] - x[0];
  accLeftBack[0] = v[0] - 2 * x[0];
  for (long long n = 1; n < N; n++) {
    accLeft[n] = accLeft[n - 1] + v[n] - (x[n] - x[n - 1]);
    accLeftBack[n] = accLeftBack[n - 1] + v[n] - 2 * (x[n] - x[n - 1]);
  }
  accRight[N - 1] = v[N - 1] - (C - x[N - 1]);
  accRightBack[N - 1] = v[N - 1] - 2 * (C - x[N - 1]);
  for (long long n = N - 2; n >= 0; n--) {
    accRight[n] = accRight[n + 1] + v[n] - (x[n + 1] - x[n]);
    accRightBack[n] = accRightBack[n + 1] + v[n] - 2 * (x[n + 1] - x[n]);
  }
  long long vRightLeft = 0;
  {
    long long i = N;
    for (long long n = N - 1; n >= 0; n--) {
      if (v[n] - 2 * (C - x[n]) < v[n] - x[n]) {
        break;
      }
      if (vRightLeft < accRightBack[n]) {
        i = n;
        vRightLeft = accRightBack[n];
      }
    }
    long long leftmax = 0;
    for (long long n = 0; n < i; n++) {
      leftmax = max(leftmax, accLeft[n]);
    }
    vRightLeft += leftmax;
  }
  long long vLeftRight = 0;
  {
    long long i = -1;
    for (long long n = 0; n < N; n++) {
      if (v[n] - 2 * x[n] < v[n] - (C - x[n])) {
        break;
      }
      if (vLeftRight < accLeftBack[n]) {
        i = n;
        vLeftRight = accLeftBack[n];
      }
    }
    long long rightmax = 0;
    for (long long n = N - 1; n > i; n--) {
      rightmax = max(rightmax, accRight[n]);
    }
    vLeftRight += rightmax;
  }
  cout << max(vRightLeft, vLeftRight) << endl;
}
int main() {
  long long N;
  scanf("%lld", &N);
  long long C;
  scanf("%lld", &C);
  std::vector<long long> x(N);
  std::vector<long long> v(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &x[i]);
    scanf("%lld", &v[i]);
  }
  solve(N, C, std::move(x), std::move(v));
  return 0;
}
