#include <bits/stdc++.h>
using namespace std;
using namespace std;
long long geko[2][200000] = {};
long long costing[2][200000] = {};
int main() {
  long long n, c;
  cin >> n >> c;
  vector<pair<long long, long long>> inputs;
  for (long long i = 0; i < n; ++i) {
    long long a, b;
    cin >> a >> b;
    inputs.push_back(make_pair(a, b));
  }
  long long now = 0;
  for (long long i = 0; i < n; ++i) {
    now += inputs[i].second;
    geko[0][i] = now - 2 * inputs[i].first;
    costing[0][i] = now - inputs[i].first;
    if (i != 0) {
      geko[0][i] = max(geko[0][i], geko[0][i - 1]);
      costing[0][i] = max(costing[0][i], costing[0][i - 1]);
    } else {
      geko[0][i] = max(geko[0][i], 0LL);
      costing[0][i] = max(costing[0][i], 0LL);
    }
  }
  now = 0;
  for (long long i = n - 1; i >= 0; --i) {
    now += inputs[i].second;
    geko[1][i] = now - 2 * (c - inputs[i].first);
    costing[1][i] = now - (c - inputs[i].first);
    if (i != n - 1) {
      geko[1][i] = max(geko[1][i], geko[1][i + 1]);
      costing[1][i] = max(costing[1][i], costing[1][i + 1]);
    } else {
      geko[1][i] = max(geko[1][i], 0LL);
      costing[1][i] = max(costing[1][i], 0LL);
    }
  }
  long long ans = max(costing[1][0], costing[0][n - 1]);
  for (long long i = 0; i < n - 2; ++i) {
    ans = max(ans, costing[0][i] + geko[1][i + 1]);
  }
  for (long long i = n - 1; i >= 0; --i) {
    ans = max(ans, costing[1][i] + geko[0][i - 1]);
  }
  cout << ans << endl;
  return 0;
}
