#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using R = double;
const ll inf = 1LL << 50;
const ll MOD = 1e9 + 7;
struct edge {
  ll from;
  ll to;
  ll cost;
};
ll n, c;
int main() {
  cin >> n >> c;
  vector<pair<ll, ll>> data;
  for (int i = 0; i < n; ++i) {
    ll x, v;
    cin >> x >> v;
    data.push_back({x, v});
    data.push_back({x - c, v});
  }
  data.push_back({0, 0});
  sort(data.begin(), data.end());
  vector<ll> sum;
  for (int i = 0; i < data.size(); ++i) {
    for (int j = 0; j < data.size(); ++j) {
      if (i < j && j - i <= n) {
        ll temp = 0;
        for (int k = i; k <= j; k++) {
          temp += data[k].second;
        }
        if (data[j].first <= 0) {
          temp -= abs(data[i].first);
        } else if (data[i].first >= 0) {
          temp -= data[j].first;
        } else {
          temp -= 2 * min(abs(data[i].first), abs(data[j].first)) +
                  max(abs(data[i].first), abs(data[j].first));
        }
        sum.push_back(temp);
      }
    }
  }
  ll ans = -inf;
  for (int i = 0; i < sum.size(); ++i) {
    ans = max(ans, sum[i]);
  }
  if (ans < 0)
    cout << 0 << endl;
  else
    cout << ans << endl;
  return 0;
}
