#include <bits/stdc++.h>
using namespace std;
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long N, C;
  cin >> N >> C;
  vector<long long> X(N), V(N), sum1(N, 0), sum2(N, 0), max1(N, 0), max2(N, 0);
  for (int i = (0); i < (N); ++i) cin >> X[i] >> V[i];
  sum1[0] = V[0];
  sum2[0] = V[N - 1];
  cerr << sum1[0] << " " << sum2[0] << endl;
  for (int i = (1); i < (N); ++i) {
    sum1[i] = sum1[i - 1] + V[i];
    sum2[i] = sum2[i - 1] + V[N - 1 - i];
    cerr << sum1[i] << " " << sum2[i] << endl;
  }
  cerr << endl;
  max1[0] = sum1[0] - X[0];
  max2[0] = sum2[0] - (C - X[N - 1]);
  cerr << max1[0] << " " << max2[0] << endl;
  for (int i = (1); i < (N); ++i) {
    max1[i] = max(max1[i - 1], sum1[i] - X[i]);
    max2[i] = max(max2[i - 1], sum2[i] - (C - X[N - 1 - i]));
    cerr << max1[i] << " " << max2[i] << endl;
  }
  long long ret = max2[N - 1];
  for (int i = (0); i < (N); ++i) {
    ret = max(ret, max1[i]);
    ret = max(ret, max2[i]);
    if (1 < N) ret = max(ret, max1[i] - X[i] + max2[N - 2 - i]);
    if (1 < N) ret = max(ret, max2[i] - (C - X[N - 1 - i]) + max1[N - 2 - i]);
  }
  cout << max(0LL, ret) << endl;
  return 0;
}
