#include <bits/stdc++.h>
using namespace std;
int main() {
  long N;
  long long C;
  long long x[100002] = {};
  long long v[100002] = {};
  long long t_cal[10] = {};
  long long rt_cal[10] = {};
  long long t_ans = 0, rt_ans = 0;
  long long ans = 0;
  cin >> N >> C;
  for (long i = 0; i < N; i++) cin >> x[i] >> v[i];
  long long vaccum = 0;
  for (long i = 0; i < N; i++) {
    vaccum += v[i];
    t_cal[i] = vaccum - x[i];
  }
  vaccum = 0;
  for (long i = N - 1; i >= 0; i--) {
    vaccum += v[i];
    rt_cal[i] = vaccum - (C - x[i]);
  }
  for (long i = 0; i < N; i++) {
    t_ans = max(
        t_ans, t_cal[i] + max((long long)0,
                              *max_element(rt_cal + i + 1, rt_cal + N) - x[i]));
  }
  for (long i = N - 1; i > 0; i--) {
    rt_ans = max(rt_ans,
                 rt_cal[i] + max((long long)0,
                                 *max_element(t_cal, t_cal + i) - (C - x[i])));
  }
  ans = max(t_ans, rt_ans);
  cout << ans << endl;
  return 0;
}
