#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N, C;
  cin >> N >> C;
  vector<long long> x(N + 2, 0);
  vector<long long> v(N + 2, 0);
  for (int i = 0; i < (N); ++i) scanf("%lld %lld", &x[i + 1], &v[i + 1]);
  x[N + 1] = C;
  vector<long long> A(N + 1, 0);
  vector<long long> B(N + 1, 0);
  vector<long long> X(N + 1, 0);
  vector<long long> Y(N + 1, 0);
  for (int i = 0; i < (N); ++i) A[i + 1] = A[i] + v[i + 1] - (x[i + 1] - x[i]);
  for (int i = 0; i < (N); ++i)
    B[i + 1] = B[i] + v[N - i] - ((C - x[N - i]) - (C - x[N - i + 1]));
  auto Bitr = B.end();
  for (int i = (1); i < (N + 1); ++i) {
    Bitr--;
    X[i] = A[i] - x[i] + *max_element(B.begin(), Bitr);
  }
  auto Aitr = A.end();
  for (int i = (1); i < (N + 1); ++i) {
    Aitr--;
    Y[i] = B[i] - (C - x[N + 1 - i]) + *max_element(A.begin(), Aitr);
  }
  cout << max(
      max(*max_element(begin(A), end(A)), *max_element(begin(B), end(B))),
      max(*max_element(begin(X), end(X)), *max_element(begin(Y), end(Y))));
}
