#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, c;
  cin >> n >> c;
  if (n > 100) {
    return 0;
  }
  vector<long long> x(n, 0), v(n, 0);
  for (int i = 0; i < n; i++) {
    cin >> x[i] >> v[i];
  }
  long long cal = 0;
  vector<long long> cal1(n + 1, 0), cal2(n + 1, 0);
  for (int i = 0; i < n; i++) {
    cal += v[i];
    cal1[i + 1] = cal;
  }
  auto v2 = v;
  auto x2 = x;
  reverse(v2.begin(), v2.end());
  reverse(x2.begin(), x2.end());
  cal = 0;
  for (int i = 0; i < n; i++) {
    cal += v2[i];
    x2[i] = c - x2[i];
    cal2[i + 1] = cal;
  }
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    ans = max(ans, cal1[i + 1] - x[i]);
    ans = max(ans, cal2[i + 1] - x2[i]);
    for (int j = 0; i + j < n - 1; j++) {
      ans = max(ans, cal1[i + 1] + cal2[j + 1] - (x[i] * 2 + x2[j]));
      ans = max(ans, cal1[j + 1] + cal2[i + 1] - (x[i] + x2[j] * 2));
    }
  }
  cout << ans << endl;
  return 0;
}
