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