#include <bits/stdc++.h>
using namespace std;
struct Block {
  long long int pos, cost;
};
int main() {
  long long int n, c;
  cin >> n >> c;
  vector<long long int> x(n + 2, 0);
  vector<long long int> v(n + 2, 0);
  for (auto i = 0; i < (n); i++) cin >> x[i + 1] >> v[i + 1];
  x[n + 1] = c;
  long long int maxx = 0;
  vector<Block> rights(n + 1);
  long long int rsum = 0;
  for (auto i = 0; i < (n + 1); i++) {
    rsum += v[i];
    maxx = max(maxx, rsum - x[i]);
    rights[i] = {i, rsum - x[i]};
  }
  vector<Block> lefts(n + 1);
  long long int lsum = 0;
  for (auto i = 0; i < (n + 1); i++) {
    long long int idx = n + 1 - i;
    lsum += v[idx];
    maxx = max(maxx, lsum - (c - x[idx]));
    lefts[idx] = {idx, lsum - (c - x[idx])};
  }
  for (auto l = 0; l < (n + 1); l++) {
    for (long long int r = l - 1; 0 <= r; r--) {
      long long int sum = lefts[l].cost + rights[r].cost;
      maxx = max(maxx, sum - x[rights[r].pos]);
      maxx = max(maxx, sum - (c - x[lefts[l].pos]));
    }
  }
  cout << maxx << endl;
  return 0;
}
