#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;
long long min_half(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]);
  }
  long long ret = g[n];
  for (long long i = 1; i < n; i++) {
    long long y = g[i - 1] + f[n] - f[i] - 2 * (c - x[i]);
    ret = max(ret, y);
  }
  return ret;
}
signed main() {
  cin >> n >> c;
  x.resize(n);
  v.resize(n);
  for (long long i = 0; i < n; i++) {
    cin >> x[i] >> v[i];
  }
  long long ans1 = min_half(x, v);
  vector<long long> z(n);
  for (long long i = 0; i < n; i++) z[i] = c - x[n - 1 - i];
  reverse(begin(v), end(v));
  long long ans2 = min_half(z, v);
  cout << min(ans1, ans2) << endl;
}
