#include <bits/stdc++.h>
using namespace std;
using lli = long long int;
int main() {
  lli n, c;
  cin >> n >> c;
  vector<lli> x(n), v(n);
  for (lli i = 0; i < (n); i++) cin >> x[i] >> v[i];
  lli cur = 0, ans = 0, s = 0, v1 = 0, v2 = 0;
  for (lli i = 0; i < (n); i++) {
    s += v[i];
    ans = max(ans, -x[i] + s);
    if (x[i] * 2 < c) v1 = max(-2 * x[i] + s, v1);
  }
  s = 0;
  for (lli i = (n)-1; i >= 0; i--) {
    s += v[i];
    ans = max(ans, -c + x[i] + s);
    if ((c - x[i]) * 2 < c) v2 = max(-2 * (c - x[i]) + s, v2);
  }
  s = 0;
  for (lli i = 0; i < (n); i++) {
    s += v[i];
    if (x[i] * 2 <= c) ans = max(-x[i] + s + v2, ans);
  }
  s = 0;
  for (lli i = (n)-1; i >= 0; i--) {
    s += v[i];
    if ((c - x[i]) * 2 <= c) ans = max(-(c - x[i]) + s + v1, ans);
  }
  cout << ans << endl;
}
