#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <typename BinOp>
void psum(vector<pair<int, ll>> const &xv, vector<ll> &target, BinOp binop) {
  ll res = 0ll;
  for (int i = 0; i < (int)xv.size(); i++) {
    res = binop(res, xv[i]);
    target[i] = res;
  }
}
int main() {
  int N;
  ll C;
  cin >> N >> C;
  vector<pair<ll, ll>> xv(N);
  for (int i = 0; i < N; i++) cin >> xv[i].first >> xv[i].second;
  sort(xv.begin(), xv.end());
  vector<ll> xs(N);
  {
    ll tmp = 0;
    for (int i = 0; i < N; i++) {
      tmp += xv[i].second;
      xs[i] = tmp - xv[i].first;
    }
  }
  vector<pair<ll, ll>> revxv(xv);
  reverse(revxv.begin(), revxv.end());
  vector<ll> revxs(N);
  {
    ll tmp = 0;
    for (int i = 0; i < N; i++) {
      tmp += revxv[i].second;
      revxs[i] = tmp - (C - revxv[i].first);
    }
  }
  copy(revxs.begin(), revxs.end(), ostream_iterator<ll>(cerr, ","));
  cerr << endl;
  vector<ll> revxvpmpos(N);
  {
    ll tmp = revxs[0];
    int curmax = 0;
    for (int i = 0; i < N; i++) {
      if (tmp < revxs[i]) {
        curmax = i;
        tmp = revxs[i];
      }
      revxvpmpos[i] = curmax;
    }
  }
  copy(revxvpmpos.begin(), revxvpmpos.end(), ostream_iterator<ll>(cerr, ","));
  cerr << endl;
  ll opt = 0;
  for (int turn = -1; turn < N; turn++) {
    ll got = 0;
    if (turn != -1) got = xs[turn];
    cerr << "turn at " << turn << " (pos " << (turn == -1 ? 0 : xv[turn].first)
         << ")"
         << " will give you " << got << endl;
    ll will_get = 0;
    int revxsmpos = -1;
    if (turn < N - 1) {
      revxsmpos = revxvpmpos[N - 2 - turn];
      will_get = (turn == -1 ? 0 : -xv[turn].first) + revxs[revxsmpos];
    }
    cerr << "  ... and if you turn back to " << revxsmpos << " (pos "
         << (revxsmpos == -1 ? 0 : revxv[revxsmpos].first) << ")"
         << " you will get " << will_get << endl;
    opt = max(opt, got + max(0ll, will_get));
  }
  cout << opt << endl;
  return 0;
}
