#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  long long int c;
  cin >> n >> c;
  long long int x[100001], v[100001];
  for (int i = 0; i < n; i++) {
    cin >> x[i] >> v[i];
  }
  if (n == 1) {
    cout << max((long long int)0, v[0] - min(x[0], c - x[0])) << endl;
    return 0;
  }
  long long int getcal[100001], getcal_rev[100001];
  getcal[0] = v[0];
  getcal_rev[n - 1] = v[n - 1];
  for (int i = 1; i < n; i++) {
    getcal[i] = getcal[i - 1] + v[i];
  }
  for (int i = n - 2; i >= 0; i--) {
    getcal_rev[i] = getcal_rev[i + 1] + v[i];
  }
  pair<long long int, int> result[100001], result_rev[100001];
  if (getcal[0] - 2 * x[0] < 0)
    result[0] = make_pair(0, -1);
  else
    result[0] = make_pair(getcal[0] - 2 * x[0], 0);
  if (getcal_rev[n - 1] - 2 * (c - x[n - 1]) < 0)
    result_rev[n - 1] = make_pair(0, -1);
  else
    result_rev[n - 1] =
        make_pair(getcal_rev[n - 1] - 2 * (c - x[n - 1]), n - 1);
  for (int i = 1; i < n; i++) {
    if (result[i - 1].first >= getcal[i] - 2 * x[i])
      result[i] = result[i - 1];
    else
      result[i] = make_pair(getcal[i] - 2 * x[i], i);
  }
  for (int i = n - 2; i >= 0; i--) {
    if (result_rev[i + 1].first >= getcal_rev[i] - 2 * (c - x[i]))
      result_rev[i] = result_rev[i + 1];
    else
      result_rev[i] = make_pair(getcal_rev[i] - 2 * (c - x[i]), i);
  }
  long long int ans = result_rev[1].first + result[0].first;
  if (result[0].second >= 0) ans += x[0];
  for (int i = 1; i < n - 1; i++) {
    ans = max(ans, max(result[i - 1].first + result_rev[i].first + c -
                           x[result_rev[i].second],
                       result_rev[i + 1].first + result[i].first +
                           x[result[i].second]));
  }
  long long int tmp = result[n - 2].first + result_rev[n - 1].first;
  if (result_rev[n - 1].second >= 0) tmp += c - x[n - 1];
  ans = max(ans, tmp);
  cout << ans << endl;
  return 0;
}
