#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, c, xi, vi, x, v, ans;
  vector<pair<long long int, long long int> > sushi;
  long long int v_t1[100005], v_t2[100005];
  cin >> n >> c;
  if (n > 100) {
    cout << 0 << endl;
    return 0;
  }
  sushi.push_back(make_pair(0, 0));
  for (int i = 0; i < n; i++) {
    cin >> xi >> vi;
    sushi.push_back(make_pair(xi, vi));
  }
  v_t1[0] = 0;
  v_t2[0] = 0;
  for (int i = 1; i <= n; i++) {
    v_t1[i] = v_t1[i - 1] + sushi[i].second;
    v_t2[i] = v_t2[i - 1] + sushi[n - (i - 1)].second;
  }
  ans = 0;
  for (int i = 1; i <= n; i++) {
    x = sushi[i].first;
    v = v_t1[i];
    ans = max(ans, v - x);
    x = c - sushi[i].first;
    v = v_t2[n - (i - 1)];
    ans = max(ans, v - x);
  }
  for (int i = 1; i <= n; i++) {
    for (int k = i + 1; k <= n; k++) {
      x = min(2 * sushi[i].first + (c - sushi[k].first),
              2 * (c - sushi[k].first) + sushi[i].first);
      v = v_t1[i] + v_t2[n - (k - 1)];
      ans = max(ans, v - x);
    }
  }
  printf("%lld\n", ans);
  return 0;
}
