#include <bits/stdc++.h>
using namespace std;
int main(void) {
  long long n, c;
  cin >> n >> c;
  vector<pair<long long, long long> > vs(n);
  for (long long i = 0; i < n; i++) {
    cin >> vs[i].first >> vs[i].second;
  }
  vector<long long> cs1(n + 1, 0);
  vector<long long> mcs1(n + 1, 0);
  for (long long i = 0; i < n; i++) {
    cs1[i + 1] = cs1[i] + vs[i].second;
    mcs1[i + 1] = max(mcs1[i], cs1[i + 1] - vs[i].first);
  }
  vector<long long> cs2(n + 1, 0);
  vector<long long> mcs2(n + 1, 0);
  for (long long i = 0; i < n; i++) {
    cs2[i + 1] = cs2[i] + vs[n - 1 - i].second;
    mcs2[i + 1] = max(mcs2[i], cs2[i + 1] - (c - vs[n - 1 - i].first));
  }
  long long m = max(0LL, max(mcs1[n], mcs2[n]));
  for (long long i = 0; i < n; i++) {
    auto m1 = mcs1[i + 1] + mcs2[n - 1 - i] - vs[i].first;
    auto m2 = mcs1[i + 1] + mcs2[n - 1 - i] - (c - vs[n - 1 - i].first);
    auto m3 = mcs2[i + 1] + mcs1[n - 1 - i] - (c - vs[n - 1 - i].first);
    auto m4 = mcs2[i + 1] + mcs1[n - 1 - i] - vs[i].first;
    m = max(m, m1);
    m = max(m, m2);
    m = max(m, m3);
    m = max(m, m4);
  }
  cout << m << endl;
  return 0;
}
