#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  long long C;
  cin >> N >> C;
  vector<long long> x(N + 1), v(N + 1);
  for (int i = 1; i <= N; i++) cin >> x[i] >> v[i];
  vector<long long> a0(N + 2, 0), a1(N + 2, 0), a3(N + 2, 0), a4(N + 2, 0);
  vector<long long> b0(N + 2, 0), b1(N + 2, 0);
  for (int i = 1; i <= N; i++) b0[i] = b0[i - 1] + v[i];
  for (int i = N; i >= 1; i--) b1[i] = b1[i + 1] + v[i];
  for (int i = 1; i <= N; i++) a0[i] = b0[i] - x[i];
  for (int i = N; i >= 0; i--) a1[i] = b1[i] - (C - x[i]);
  int id0 = 1, id1 = N;
  for (int i = 1; i <= N; i++)
    if (x[i] <= C / 2) id0 = i;
  for (int i = N; i >= 0; i--)
    if (C - x[i] <= C / 2) id1 = i;
  vector<long long> aa0(N + 2, 0), aa1(N + 2, 0);
  for (int i = 1; i <= id0; i++) aa0[i] = a0[i];
  for (int i = N; i >= id1; i--) aa1[i] = a1[i];
  for (int i = N; i > id0; i--) a3[i] = b1[i] - 2 * (C - x[i]);
  for (int i = 1; i < id1; i++) a4[i] = b0[i] - 2 * x[i];
  long long ans = 0;
  sort(a0.begin(), a0.end());
  sort(a1.begin(), a1.end());
  sort(a3.begin(), a3.end());
  sort(a4.begin(), a4.end());
  sort(aa0.begin(), aa0.end());
  sort(aa1.begin(), aa1.end());
  ans = max(ans, a0.back());
  ans = max(ans, a1.back());
  ans = max(ans, aa0.back() + a3.back());
  ans = max(ans, aa1.back() + a4.back());
  cout << ans << endl;
  return 0;
}
