#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] = {};
  x[n + 1] = c;
  for (int i = 1; i <= n; i++) {
    cin >> x[i] >> v[i];
  }
  if (n == 1) {
    cout << max((long long int)0, v[1] - min(x[1], c - x[1])) << endl;
    return 0;
  }
  long long int getcal[100010] = {}, getcal_rev[100010] = {};
  for (int i = 1; i <= n; i++) {
    getcal[i] = getcal[i - 1] + v[i];
  }
  for (int i = n; i >= 1; i--) {
    getcal_rev[i] = getcal_rev[i + 1] + v[i];
  }
  pair<long long int, int> result[100010], result_rev[100010];
  result[0] = make_pair(0, 0);
  result_rev[n + 1] = make_pair(0, 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; i >= 1; 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 = 0;
  for (int i = 1; i <= n; 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]));
  }
  cout << ans << endl;
  return 0;
}
