#include <bits/stdc++.h>
using namespace std;
template <class T1, class T2>
void chmin(T1 &a, T2 b) {
  if (a > b) a = b;
}
template <class T1, class T2>
void chmax(T1 &a, T2 b) {
  if (a < b) a = b;
}
using Pi = pair<long long, long long>;
using Tapris = tuple<long long, long long, long long>;
using vint = vector<long long>;
const long long inf = 1LL << 55;
const long long mod = 1e9 + 7;
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);
  long long n, c;
  cin >> n >> c;
  vint x(n), v(n);
  for (long long i = (long long)(0); i < (long long)(n); i++)
    cin >> x[i] >> v[i];
  vint rv(n + 1);
  vint mi(n + 1);
  long long mx = 0;
  mi[0] = 1;
  for (long long i = (long long)(0); i < (long long)(n); i++) {
    rv[i + 1] = rv[i] + v[i];
    chmax(mx, rv[i + 1] - x[i]);
    if (rv[mi[i]] - x[mi[i] - 1] < rv[i + 1] - x[i])
      mi[i + 1] = i + 1;
    else
      mi[i + 1] = mi[i];
  }
  long long res = max(0ll, mx);
  long long sum = 0;
  for (long long i = n - 1; i >= 0; --i) {
    sum += v[i];
    cout << mi[i] << " " << rv[mi[i]] << " " << x[mi[i] - 1] << endl;
    if (i == 0)
      chmax(res, sum - (c - x[i]));
    else {
      chmax(res, sum - 2 * (c - x[i]) + rv[mi[i]] - x[mi[i] - 1]);
      chmax(res, sum - (c - x[i]) + rv[mi[i]] - 2 * x[mi[i] - 1]);
    }
  }
  cout << res << endl;
  return 0;
}
