#include <bits/stdc++.h>
using namespace std;
long long n, c;
int main() {
  cin >> n >> c;
  vector<pair<long long, long long>> xv(n);
  for (int i = 0; i < n; i++) {
    cin >> xv[i].first >> xv[i].second;
  }
  if (n > 100) {
    return 0;
  }
  long long ans = 0;
  long long rsum = 0, lsum = 0;
  for (int i = 0; i < n; i++) {
    lsum = 0;
    rsum += xv[i].second;
    ans = max(ans, rsum - xv[i].first);
    for (int j = n - 1; j > i; j--) {
      lsum += xv[j].second;
      ans = max(ans, rsum + lsum - (xv[i].first * 2 + c - xv[j].first));
    }
  }
  lsum = 0;
  rsum = 0;
  for (int i = n - 1; i >= 0; i--) {
    rsum = 0;
    lsum += xv[i].second;
    ans = max(ans, lsum - (c - xv[i].first));
    for (int j = 0; j < i; j++) {
      rsum += xv[j].second;
      ans = max(ans, rsum + lsum - ((c - xv[i].first) * 2 + xv[j].first));
    }
  }
  cout << ans << endl;
  return 0;
}
