#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  long long C;
  cin >> N >> C;
  vector<long long> Xs, Vs, Vcw, Vccw;
  map<long long, long long> sushi;
  Xs.push_back(0);
  Vs.push_back(0);
  Vcw.push_back(0);
  long long vcw = 0, vccw = 0;
  for (int i = 0; i < N; ++i) {
    long long x, v;
    cin >> x >> v;
    Xs.push_back(x);
    Vs.push_back(v);
    vcw += v;
    Vcw.push_back(vcw);
  }
  Xs.push_back(C);
  Vccw.push_back(0);
  for (int i = 0; i < N; ++i) {
    vcw -= Vs[i];
    Vccw.push_back(vcw);
  }
  Vccw.push_back(0);
  long long ans = 0;
  for (int cw = 0; cw <= N; ++cw) {
    for (int ccw = N + 1; ccw > cw; --ccw) {
      long long v = Vcw[cw] + Vccw[ccw];
      long long x1 = 2 * Xs[cw] + C - Xs[ccw];
      long long x2 = 2 * (C - Xs[ccw]) + Xs[cw];
      ans = max({ans, v - x1, v - x2});
    }
  }
  cout << ans << endl;
  return 0;
}
