#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ll n, c;
  cin >> n >> c;
  vector<ll> x(n), v(n);
  for (int i = (0); i < (n); i++) cin >> x[i] >> v[i];
  vector<ll> cumsum(n + 1), cumsum_rev(n + 1);
  cumsum[0] = cumsum_rev[0] = 0;
  for (int i = (0); i < (n); i++) {
    cumsum[i + 1] = cumsum[i] + v[i];
    cumsum_rev[i + 1] = cumsum_rev[i] + v[n - i - 1];
  }
  vector<ll> back(n + 1), back_rev(n + 1);
  back[0] = back_rev[0] = 0;
  for (int i = (0); i < (n); i++) {
    back[i + 1] = max(back[i], cumsum[i + 1] - x[i] * 2);
    back_rev[i + 1] =
        max(back_rev[i], cumsum_rev[i + 1] - (c - x[n - i - 1]) * 2);
  }
  ll ans = 0;
  for (int i = (0); i < (n - 1); i++) {
    ll cand1 = cumsum[i + 1] + back_rev[n - i - 1] - x[i];
    ll cand2 = cumsum_rev[i + 1] + back[n - i - 1] - (c - x[n - 1 - i]);
    ans = max(ans, cand1);
    ans = max(ans, cand2);
  }
  cout << ans << endl;
  return 0;
}
