#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7, LINF = 1e18 + 1e16;
const int INF = 1e9 + 1;
const double EPS = 1e-10;
const int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};
const long long P1 = 31, P2 = 37, M1 = 1e9 + 7, M2 = 1e9 + 9;
const int N = 1e5 + 1;
int n;
long long C, x[N], v[N], ans, pref[N], prefx[N], suff[N], suffx[N], mxsuff[N],
    mxsuffx[N];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ;
  cin >> n >> C;
  for (int i = 0; i < n; i++) cin >> x[i] >> v[i];
  for (int i = 0; i < n; i++) {
    pref[i] = (i ? pref[i - 1] : 0) + v[i];
  }
  for (int i = n - 1; i >= 0; i--) {
    suff[i] = (i < n - 1 ? suff[i + 1] : 0) + v[i];
    mxsuff[i] = max((i < n - 1 ? mxsuff[i + 1] : 0), suff[i] - (C - x[i]));
    mxsuffx[i] =
        max((i < n - 1 ? mxsuffx[i + 1] : 0), suff[i] - 2ll * (C - x[i]));
  }
  for (int i = 0; i < n; i++) {
    ans = max(pref[i] - 2 * x[i] + (i < n - 1 ? mxsuff[i + 1] : 0), ans);
    ans = max(pref[i] - x[i] + (i < n - 1 ? mxsuffx[i + 1] : 0), ans);
  }
  cout << ans;
}
