#include <bits/stdc++.h>
using namespace std;
long long n;
long long c;
vector<long long> x, v;
vector<long long> f, g;
long long inf = 1e18;
void fill_vector(vector<long long> a, vector<long long> b) {
  f.resize(n + 1, 0);
  g.resize(n + 1, 0);
  for (long long i = 0; i < n; i++) {
    f[i + 1] = f[i] + b[i];
  }
  for (long long i = 0; i < n; i++) {
    g[i + 1] = max(g[i], f[i + 1] - a[i]);
  }
}
signed main() {
  cin >> n >> c;
  x.resize(n);
  v.resize(n);
  for (long long i = 0; i < n; i++) {
    cin >> x[i] >> v[i];
  }
  fill_vector(x, v);
  long long ans = max(g[n], f[n] - min(c - x[0], x[n - 1]));
  cerr << ans << endl;
  for (long long i = 0; i < n - 1; i++) {
    long long y = g[i + 1] + f[n] - f[i + 1] - 2 * (c - x[i + 1]);
    ans = max(ans, y);
  }
  cout << endl;
  reverse(begin(x), end(x));
  reverse(begin(v), end(v));
  fill_vector(x, v);
  ans = max(ans, g[n]);
  for (long long i = 0; i < n - 1; i++) {
    long long y = g[i + 1] + f[n] - f[i + 1] - 2 * (c - x[i + 1]);
    ans = max(ans, y);
  }
  cout << ans << endl;
}
