#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
int main() {
  long long N, C;
  cin >> N >> C;
  vector<long long> x(N + 2, 0), v(N + 2, 0);
  for (int i = 1; i <= N; ++i) cin >> x[i] >> v[i];
  x[N + 1] = C;
  long long ans = 0;
  vector<long long> cumv(N + 2, 0), f1(N + 1, 0), g1(N + 1, 0), f2(N + 1, 0),
      g2(N + 1, 0);
  for (int i = 1; i <= N + 1; ++i) cumv[i] = cumv[i - 1] + v[i];
  for (int i = 1; i <= N; ++i) {
    f1[i] = cumv[i] - x[i];
    g1[i] = max(g1[i - 1], f1[i]);
    f2[i] = cumv[i] - 2 * x[i];
    g2[i] = max(g2[i - 1], f2[i]);
  }
  for (int b = 1; b <= N + 1; ++b) {
    chmax(ans, cumv[b] - cumv[b - 1] - 2 * (C - x[b]) + g1[b - 1]);
    chmax(ans, cumv[b] - cumv[b - 1] - (C - x[b]) + g2[b - 1]);
  }
  cout << ans << endl;
  return 0;
}
