#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N, C, x[100001], v[100001];
  cin >> N >> C;
  for (int i = 1; i <= N; ++i) {
    cin >> x[i] >> v[i];
  }
  long long v_l[100001], v_r[100001];
  v_l[0] = 0;
  v_r[0] = 0;
  for (int i = 1; i <= N; ++i) {
    v_l[i] = v_l[i - 1] + v[i];
    v_r[i] = v_r[i - 1] + v[(N + 1) - i];
  }
  long long l_0[100001], l_1[100001], r_0[100001], r_1[100001];
  l_0[0] = 0;
  l_1[0] = 0;
  r_0[0] = 0;
  r_1[0] = 0;
  for (int i = 1; i <= N; ++i) {
    l_0[i] = max(l_0[i - 1], v_l[i] - x[i]);
    l_1[i] = max(l_0[i - 1], v_l[i] - 2 * x[i]);
    r_0[i] = max(r_0[i - 1], v_r[i] - (C - x[(N + 1) - i]));
    r_1[i] = max(r_1[i - 1], v_r[i] - 2 * (C - x[(N + 1) - i]));
  }
  long long l_max0 = l_0[N], r_max0 = r_0[N];
  long long l_max1 = -1e9, r_max1 = -1e9;
  for (int i = 0; i <= N; ++i) {
    l_max1 = max(l_max1, l_1[i] + r_0[N - i]);
    r_max1 = max(r_max1, l_0[i] + r_1[N - i]);
  }
  long long ans = -1e9;
  ans = max(ans, l_max0);
  ans = max(ans, r_max0);
  ans = max(ans, l_max1);
  ans = max(ans, r_max1);
  cout << ans << endl;
  return 0;
}
