#include <bits/stdc++.h>
using namespace std;
long long ans[123456], revans[123456], revv[123456], v[123456], revx[123456];
long long x[123456], maxi, wow, baba[123456], revbaba[123456];
int main() {
  std::ios::sync_with_stdio(false);
  long long n, c;
  long long i;
  cin >> n >> c;
  for (i = 1; i < n + 1; i++) {
    cin >> x[i] >> v[i];
    revx[n - i + 1] = x[i];
    revv[n - i + 1] = v[i];
  }
  for (i = 1; i < n + 1; i++) {
    ans[i] = ans[i - 1] + v[i];
    maxi = max(maxi, ans[i] - x[i]);
    revans[i] = revans[i - 1] + revv[i];
    maxi = max(maxi, revans[i] - c + revx[i]);
  }
  for (i = 1; i < n + 1; i++) {
    baba[i] = max(baba[i - 1], ans[i] - x[i]);
    revbaba[i] = max(revbaba[i - 1], revans[i] - c + revx[i]);
  }
  for (i = 1; i < n; i++) {
    wow = ans[i] - 2 * x[i] + revbaba[n - i - 1];
    maxi = max(maxi, wow);
    wow = revans[i] - 2 * c + 2 * revx[i] + baba[n - i - 1];
    maxi = max(maxi, wow);
  }
  cout << maxi << endl;
  return 0;
}
