#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ll n, c;
  cin >> n >> c;
  ll x[n], v[n];
  ll score[n + 1];
  score[0] = 0;
  ll totalscore[n + 1];
  totalscore[0] = 0;
  ll maxscore[n + 1];
  maxscore[0] = 0;
  ll maxpos[n + 1];
  maxpos[0] = 0;
  for (int i = 0; i < n; i++) {
    cin >> x[i] >> v[i];
    totalscore[i + 1] = totalscore[i] + v[i];
    score[i + 1] = totalscore[i + 1] - x[i];
    maxscore[i + 1] = max(maxscore[i], score[i + 1]);
    if (maxscore[i] >= score[i + 1]) {
      maxpos[i + 1] = maxpos[i];
    } else {
      maxpos[i + 1] = x[i];
    }
  }
  ll ans = maxscore[n];
  ll revtotal[n + 1];
  revtotal[n] = 0;
  for (int i = n - 1; i >= 1; i--) {
    revtotal[i] = revtotal[i + 1] + v[i];
    ll temp = max(maxscore[i] + revtotal[i] - (c - x[i]) - maxpos[i],
                  maxscore[i] + revtotal[i] - (c - x[i]) * 2);
    ans = max(ans, temp);
  }
  revtotal[0] = revtotal[1] + v[0];
  ll temp = revtotal[0] - (c - x[0]);
  ans = max(ans, temp);
  cout << ans << endl;
}
