#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;
  }
  vector<long long> f, g, f2, g2;
  g.push_back(0);
  g2.push_back(0);
  for (int i = (0); i < (N); ++i) {
    f[i] = sumA[i + 1] - v[i].first;
    f2[i] = sumA[i + 1] - 2 * v[i].first;
    g[i + 1] = max(g[i], f[i]);
    g2[i + 1] = max(g2[i], f2[i]);
  }
  long long res = 0;
  for (int b = (0); b < (N + 1); ++b) {
    long long OB = b == N ? 0 : C - v[b].first;
    res = max(res, max(g[b - 1] + sumB[b] - 2 * OB, g2[b - 1] + sumB[b] - OB));
  }
  cout << res << endl;
  return 0;
}
