#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 + 1);
  vector<long long> accRight(N + 1);
  for (int(n) = 0; (n) < (N); ++(n)) {
    if (n == 0) {
      accLeft[n] = v[n] - x[n];
    } else {
      accLeft[n] = v[n] + x[n - 1] - x[n] + accLeft[n - 1];
    }
  }
  for (int(n) = (N)-1; (n) >= 0; --(n)) {
    if (n == N) {
      accRight[n] = 0;
    } else if (n == N - 1) {
      accRight[n] = v[n] - (C - x[n]);
    } else {
      accRight[n] = v[n] + (C - x[n + 1]) - (C - x[n]) + accRight[n + 1];
    }
  }
  int i = 0;
  long long leftRight = 0;
  for (int(n) = 0; (n) < (N); ++(n)) {
    if (accLeft[n] > 0 && v[n] - x[n] > v[n] - (C - x[n])) {
      if (leftRight < accLeft[n]) {
        i = n;
        leftRight = accLeft[i];
      }
    }
  }
  long long leftRightTmp = 0;
  for (int j = i + 1; j < N; j++) {
    long long tmp = accRight[j] - (C - x[j]);
    if (tmp > 0 && leftRightTmp < tmp) {
      leftRightTmp = tmp;
    }
  }
  leftRight += leftRightTmp;
  long long rightLeft = 0;
  for (int(n) = (N)-1; (n) >= 0; --(n)) {
    if (accRight[n] > 0 && v[n] - (C - x[n]) > v[n] - x[n]) {
      if (rightLeft < accRight[n]) {
        i = n;
        rightLeft = accRight[i];
      }
    }
  }
  long long rightLeftTmp = 0;
  for (int j = i - 1; j >= 0; j--) {
    long long tmp = accLeft[j] - x[j];
    if (tmp > 0 && rightLeftTmp < tmp) {
      rightLeftTmp = tmp;
    }
  }
  rightLeft += rightLeftTmp;
  cout << max(leftRight, rightLeft) << 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;
}
