#include <bits/stdc++.h>
using namespace std;
int main(void) {
  long ans, N, C, x[100002], v[100002], dif[100002], dif_r[100002], ret, ret_r;
  x[0] = (long)0;
  ret = (long)0;
  ret_r = (long)0;
  v[0] = (long)0;
  dif[0] = (long)0;
  dif_r[0] = (long)0;
  vector<long> d, d_r, d_ret, d_ret_r, V, V_r;
  scanf("%ld%ld", &N, &C);
  x[N + 1] = C;
  for (int i = 1; i < N + 1; i++) {
    scanf("%ld%ld", &x[i], &v[i]);
    dif[i] = dif[i - 1] + v[i] + x[i - 1] - x[i];
    d.push_back(dif[i]);
  }
  for (int i = N; i > 0; i--) {
    dif_r[N - i + 1] = dif_r[N - i] + v[i] + (C - x[i + 1]) - (C - x[i]);
    d_r.push_back(dif_r[N - i + 1]);
    if (dif_r[N - i + 1] - (C - x[i]) > ret_r)
      ret_r = dif_r[N - i + 1] - (C - x[i]);
    d_ret_r.push_back(ret_r);
  }
  for (int i = 1; i < N + 1; i++) {
    if (dif[i] - x[i] > ret) ret = dif[i] - x[i];
    d_ret.push_back(ret);
    V_r.push_back(d_r[i - 1] + d_ret[N - i]);
  }
  for (int i = N; i > 0; i--) {
    V.push_back(d[N - i] + d_ret_r[i - 1]);
  }
  sort(V.begin(), V.end(), greater<long>());
  sort(V_r.begin(), V_r.end(), greater<long>());
  if (V[0] > V_r[0])
    ans = V[0];
  else
    ans = V_r[0];
  if (ans < (long)0) ans = (long)0;
  printf("%ld\n", ans);
  fflush(stdout);
  return 0;
}
