#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long n, c;
  cin >> n >> c;
  if (n > 1000) return 0;
  vector<pair<long long, long long> > xv(n);
  for (long long i = 0; i < n; i++) {
    cin >> xv[i].first >> xv[i].second;
  }
  sort((xv).begin(), (xv).end());
  vector<long long> x(n), v(n);
  for (long long i = 0; i < n; i++) {
    x[i] = xv[i].first;
    v[i] = xv[i].second;
  }
  vector<long long> sum(n);
  for (long long i = 0; i < n; i++) {
    sum[i] = v[i];
    if (i) sum[i] += sum[i - 1];
  }
  long long res = 0;
  long long all = sum[n - 1];
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < i; j++) {
      res = max({res, (all - sum[i - 1]) + sum[j] - ((c - x[i]) + x[j] * 2),
                 (all - sum[i - 1]) + sum[j] - ((c - x[i]) * 2 + x[j])});
    }
  }
  for (long long i = 0; i < n; i++) {
    res =
        max({res, sum[i] - x[i], (i ? (all - sum[i - 1]) : all) - (c - x[i])});
  }
  cout << res << endl;
}
