#include <bits/stdc++.h>
using namespace std;
long long n;
long long c;
vector<pair<long long, long long>> xv;
vector<long long> lef, rig;
long long leftgain(int num) {
  if (num == 0) return 0;
  return lef[num] - xv[num - 1].first;
}
long long riggain(int num) {
  if (num == 0) return 0;
  long long dis = c - xv[n - num].first;
  return rig[num] - dis;
}
int main() {
  cin >> n >> c;
  xv = vector<pair<long long, long long>>(n);
  for (int i = (0); i < (int)(n); i++) cin >> xv[i].first >> xv[i].second;
  sort(xv.begin(), xv.end());
  lef = vector<long long>(n + 1, 0);
  rig = vector<long long>(n + 1, 0);
  for (int i = (1); i < (int)(n + 1); i++) {
    lef[i] += lef[i - 1] + xv[i - 1].second;
    rig[i] += rig[i - 1] + xv[n - i].second;
  }
  long long ans = 0;
  vector<long long> maxleft(n + 1, 0);
  vector<long long> maxright(n + 1, 0);
  for (int i = (1); i <= (int)(n); i++)
    maxleft[i] = max(maxleft[i - 1], leftgain(i));
  for (int i = (1); i <= (int)(n); i++)
    maxright[i] = max(maxright[i - 1], riggain(i) - (c - xv[n - i].first));
  for (int i = (0); i <= (int)(n); i++)
    ans = max(ans, maxleft[i] + maxright[n - i]);
  long long ans2 = 0;
  vector<long long> maxleft2(n + 1, 0);
  vector<long long> maxright2(n + 1, 0);
  for (int i = (1); i <= (int)(n); i++)
    maxleft2[i] = max(maxleft2[i - 1], leftgain(i) - xv[i - 1].first);
  for (int i = (1); i <= (int)(n); i++)
    maxright2[i] = max(maxright2[i - 1], riggain(i));
  for (int i = (0); i <= (int)(n); i++)
    ans2 = max(ans, maxleft2[i] + maxright2[n - i]);
  cout << max(ans, ans2);
  return 0;
}
