#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, v[100002];
  long long c, x[100002], addv[100002], ans = 0;
  cin >> n >> c;
  x[0] = 0;
  v[0] = 0;
  addv[0] = 0;
  for (int i = 1; i < n + 1; i++) {
    cin >> x[i] >> v[i];
    addv[i] = addv[i - 1] + v[i];
  }
  x[n + 1] = c;
  v[n + 1] = 0;
  for (int i = 0; i < n + 1; i++) {
    for (int j = i + 1; j <= n + 1; j++) {
      ans = max(ans, addv[n] - addv[j - 1] + addv[i] - (c - (x[j] - x[i])) -
                         min(c - x[j], x[i]));
    }
  }
  cout << ans << endl;
  return 0;
}
