#include <bits/stdc++.h>
using namespace std;
int N;
long long int C;
long long int x[100000], v[100000];
long long int left() {
  vector<long long int> lcost(N, 0LL), rcost(N, 0LL);
  lcost[0] = v[0];
  for (int i = int(1); i < int(N); i++) {
    lcost[i] = lcost[i - 1] + v[i];
  }
  for (int i = int(0); i < int(N); i++) {
    lcost[i] -= x[i];
  }
  rcost[N - 1] = v[N - 1];
  for (int i = N - 2; i >= 0; i--) {
    rcost[i] = rcost[i + 1] + v[i];
  }
  for (int i = int(0); i < int(N); i++) {
    rcost[i] -= (C - x[i]);
    rcost[i] -= (C - x[i]);
  }
  lcost[0] = max(lcost[0], 0ll);
  for (int i = int(1); i < int(N); i++) {
    lcost[i] = max(lcost[i], lcost[i - 1]);
  }
  rcost[N - 1] = max(rcost[N - 1], 0LL);
  for (int i = N - 2; i >= 0; i--) {
    rcost[i] = max(rcost[i], rcost[i + 1]);
  }
  long long int ans = -1;
  for (int i = 0; i < N - 1; i++) {
    ans = max(ans, lcost[i] + rcost[i + 1]);
  }
  return ans;
}
long long int right() {
  vector<long long int> lcost(N, 0LL), rcost(N, 0LL);
  lcost[0] = v[0];
  for (int i = int(1); i < int(N); i++) {
    lcost[i] = lcost[i - 1] + v[i];
  }
  for (int i = int(0); i < int(N); i++) {
    lcost[i] -= x[i];
    lcost[i] -= x[i];
  }
  rcost[N - 1] = v[N - 1];
  for (int i = N - 2; i >= 0; i--) {
    rcost[i] = rcost[i + 1] + v[i];
  }
  for (int i = int(0); i < int(N); i++) {
    rcost[i] -= (C - x[i]);
  }
  lcost[0] = max(lcost[0], 0ll);
  for (int i = int(1); i < int(N); i++) {
    lcost[i] = max(lcost[i], lcost[i - 1]);
  }
  rcost[N - 1] = max(rcost[N - 1], 0LL);
  for (int i = N - 2; i >= 0; i--) {
    rcost[i] = max(rcost[i], rcost[i + 1]);
  }
  long long int ans = -1;
  for (int i = 0; i < N - 1; i++) {
    ans = max(ans, lcost[i] + rcost[i + 1]);
  }
  return ans;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> N >> C;
  for (int i = int(0); i < int(N); i++) {
    cin >> x[i] >> v[i];
  }
  if (N == 1) {
    long long int ans = max({v[0] - x[0], v[0] - (C - x[0]), 0ll});
    cout << ans << endl;
    return 0;
  }
  long long int ans = max(right(), left());
  cout << ans << endl;
  return 0;
}
