#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1e5;
const long long INF = 1e18;
int N;
long long C;
long long X[MAX_N + 2], V[MAX_N + 2];
long long vsum[MAX_N + 2];
int main() {
  cin >> N >> C;
  vsum[0] = 0;
  X[0] = 0;
  V[0] = 0;
  for (int i = (0); i < (N); i++) {
    cin >> X[i + 1] >> V[i + 1];
    vsum[i + 1] = vsum[i] + V[i + 1];
  }
  long long ans = -INF;
  int mx1, mx2;
  mx1 = 0;
  mx2 = 0;
  int y = 0;
  for (int i = (0); i < (N); i++) {
    y++;
    long long ans2;
    if (vsum[mx1] - X[mx1] < vsum[i] - X[i]) {
      mx1 = i;
    }
    if (vsum[mx2] - 2 * X[mx2] < vsum[i] - 2 * X[i]) {
      mx2 = i;
    }
    if (X[mx1] >= C - X[y]) {
      ans2 = vsum[mx1] + (vsum[N] - vsum[y - 1]) - X[mx1] - (C - X[y]) -
             min<long long>(X[mx1], C - X[y]);
    } else {
      ans2 = vsum[mx2] + (vsum[N] - vsum[y - 1]) - X[mx2] - (C - X[y]) -
             min<long long>(X[mx2], C - X[y]);
    }
    ans = max(ans, ans2);
  }
  if (vsum[mx1] - X[mx1] < vsum[N] - X[N]) {
    mx1 = N;
  }
  ans = max(ans, vsum[mx1] - X[mx1]);
  cout << ans << endl;
  return 0;
}
