#include <bits/stdc++.h>
using namespace std;
long long n, c;
long long f[100005];
long long x[100005];
long long v[100005];
long long revv[100005];
int main() {
  cin >> n >> c;
  for (int i = 1; i <= n; i++) cin >> x[i] >> v[i];
  for (int i = 1; i <= n; i++) revv[i] = revv[i - 1] + v[n - i + 1];
  for (int i = 1; i <= n; i++) v[i] += v[i - 1];
  long long tmp = 0;
  long long maxm = 0;
  for (int i = 1; i <= n; i++) {
    if (maxm >= v[i] - x[i]) {
      f[i] = f[i - 1];
    } else {
      f[i] = i;
      maxm = v[i] - x[i];
    }
  }
  long long ans = v[f[n]] - x[f[n]];
  for (int i = 1; i <= n; i++) {
    long long X = min(2 * (c - x[n - i + 1]) + x[f[n - i]],
                      2 * x[f[n - i]] + c - x[n - i + 1]);
    ans = max(ans, revv[i] - X + v[f[n - i]]);
  }
  cout << ans << endl;
}
