#include <bits/stdc++.h>
using namespace std;
void CINT() {}
template <class Head, class... Tail>
void CINT(Head&& head, Tail&&... tail) {
  cin >> head;
  CINT(move(tail)...);
}
const long long LINF = 1e18 + 1;
const int MOD = 1e9 + 7;
const int MAX_N = 1e5 + 1;
int N;
long long C;
long long rSum[MAX_N];
long long lSum[MAX_N];
long long lMax[MAX_N];
long long solve(vector<long long> x, vector<long long> v) {
  for (int i = (int)0; i < (int)N; ++i) {
    if (i > 0)
      rSum[i] = rSum[i - 1] + v[i];
    else
      rSum[i] = v[i];
  }
  long long mx = 0ll;
  for (int i = (int)N - 1; i >= (int)0; --i) {
    long long cal = C - x[i];
    if (i < N - 1)
      lSum[i] = lSum[i + 1] + v[i] - cal;
    else
      lSum[i] = v[i] - cal;
    mx = max(mx, lSum[i]);
    lMax[i] = mx;
  }
  long long res = 0ll;
  for (int ub = (int)0; ub < (int)N; ++ub) {
    long long sum = 0ll;
    sum -= x[ub];
    sum += rSum[ub];
    res = max(res, sum);
    sum -= x[ub];
    if (ub < N - 1) sum += lMax[ub + 1];
    res = max(res, sum);
  }
  return res;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> N >> C;
  vector<long long> x(N);
  vector<long long> v(N);
  for (int i = (int)0; i < (int)N; ++i) {
    cin >> x[i] >> v[i];
  }
  long long ans = solve(x, v);
  reverse((x).begin(), (x).end());
  for (int i = (int)0; i < (int)N; ++i) {
    x[i] = C - x[i];
  }
  reverse((v).begin(), (v).end());
  ans = max(ans, solve(x, v));
  cout << ans << endl;
  return 0;
}
