#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const ll INF = 1e18;
inline void chmax(ll& a, ll b) { a = max(a, b); }
inline void chmin(ll& a, ll b) { a = min(a, b); }
int main() {
  ll n, c;
  cin >> n >> c;
  vector<ll> x(n);
  vector<ll> v(n);
  for (long long i = 0; i < (n); ++i) cin >> x[i] >> v[i];
  vector<ll> rieki(n);
  for (long long i = 0; i < (n); ++i) {
    if (i == 0)
      rieki[i] = v[0] - x[0];
    else
      rieki[i] = rieki[i - 1] + x[i - 1] + v[i] - x[i];
  }
  vector<ll> rmax(n);
  for (long long i = 0; i < (n); ++i) {
    if (i == 0)
      rmax[i] = rieki[i];
    else
      rmax[i] = max(rmax[i - 1], rieki[i]);
  }
  ll sum = 0;
  for (long long i = 0; i < (n); ++i) sum += v[i];
  vector<ll> lieki(n);
  for (long long i = 0; i < (n); ++i) lieki[i] = sum - c + v[i] - rieki[i];
  vector<ll> lmax(n);
  for (long long i = 0; i < (n); ++i) {
    if (i == 0)
      lmax[n - 1] = lieki[n - 1];
    else
      lmax[n - 1 - i] = max(lmax[n - i], lieki[n - 1 - i]);
  }
  ll rans = 0;
  for (long long i = 1; i <= n - 1; i++) {
    rans = max(rans, rmax[i - 1] + lieki[i] - (c - x[i]));
  }
  ll lans = 0;
  for (long long i = 0; i <= n - 2; i++) {
    lans = max(lans, rieki[i] - x[i] + lmax[i]);
  }
  ll ans = max(0ll, max(lans, max(rans, max(rmax[n - 1], lmax[0]))));
  cout << ans << endl;
  return 0;
}
