#include <bits/stdc++.h>
using namespace std;
using ll = long long;
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);
    }
  }
  vector<ll> xvpmpos(N);
  {
    ll tmp = xs[0];
    int curmax = 0;
    for (int i = 0; i < N; i++) {
      if (tmp < xs[i]) {
        curmax = i;
        tmp = xs[i];
      }
      xvpmpos[i] = curmax;
    }
  }
  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;
    }
  }
  ll opt = 0;
  for (int right = -1; right < N; right++) {
    int left = right < N - 1 ? revxvpmpos[N - 2 - right] : -1;
    {
      ll got = 0;
      if (right != -1) got = xs[right];
      ll will_get = 0;
      if (left != -1)
        will_get = (right == -1 ? 0 : -xv[right].first) + revxs[left];
      opt = max(opt, got + max(0ll, will_get));
    }
    {
      ll got = 0;
      if (left != -1) got = revxs[left];
      ll will_get = 0;
      if (right != -1)
        will_get = (left == -1 ? 0 : -(C - revxv[left].first)) + xs[right];
      opt = max(opt, got + max(0ll, will_get));
    }
  }
  cout << opt << endl;
  return 0;
}
