#include <bits/stdc++.h>
using namespace std;
int n;
long long c;
vector<long long> x, v, sum, macs, dist;
const long long INF = 1e18;
int main() {
  cin >> n >> c;
  x = v = vector<long long>(n);
  for (int i = (0); i < (n); i++) cin >> x[i] >> v[i];
  dist = sum = macs = vector<long long>(n + 1, 0);
  long long tmpMax = -INF, tmpDist = 0;
  for (int i = (0); i < (n); i++) {
    sum[i + 1] += sum[i] + v[i];
    if (tmpMax < sum[i + 1] - x[i]) {
      tmpMax = max(tmpMax, sum[i + 1] - x[i]);
      tmpDist = x[i];
    }
    dist[i + 1] = tmpDist;
    macs[i + 1] = tmpMax;
  }
  long long ans = 0, nowSum = 0;
  for (int i = (0); i < (n + 1); i++) {
    if (!i) {
      ans = max(ans, macs[n]);
      continue;
    }
    nowSum += v[n - i];
    ans = max({ans, nowSum + macs[n - i] - (c - x[n - i]) * 2,
               nowSum - c + x[n - i],
               nowSum + macs[n - i] - c + x[n - i] - dist[n - i + 1]});
  }
  cout << ans << endl;
  return 0;
}
