#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N, C;
  cin >> N >> C;
  vector<pair<long long, long long> > v;
  for (int i = (0); i < (N); ++i) {
    long long x, _v;
    cin >> x >> _v;
    v.push_back(make_pair(x, _v));
  }
  vector<long long> sumA, sumB(N + 1, 0);
  sumA.push_back(0);
  for (int i = (0); i < (N); ++i) {
    sumA.push_back(sumA[i] + v[i].second);
  }
  sumB[0] = sumA.back();
  for (int i = (0); i < (N); ++i) {
    sumB[i + 1] = sumB[i] - v[i].second;
  }
  long long res = 0;
  for (int a = (0); a < (N + 1); ++a) {
    for (int b = N; b >= a; --b) {
      long long OA = a == 0 ? 0 : v[a - 1].first,
                OB = b == N ? 0 : C - v[b].first;
      res = max(res, sumA[a] + sumB[b] - min(2 * OA + OB, OA + 2 * OB));
    }
  }
  cout << res << endl;
  return 0;
}
