#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18 + 1;
signed main() {
  long long n, c;
  cin >> n >> c;
  long long x[100001], v[100001];
  vector<long long> r;
  long long sum = 0;
  for (long long i = 0; i < n; i++) {
    cin >> x[i] >> v[i];
    sum += v[i];
  }
  long long ans = 0;
  long long s = 0;
  long long w = 0;
  long long ma[100001] = {0};
  for (long long i = n - 1; i >= 0; i--) {
    s += v[i];
    ma[i] = max(ma[i + 1], s - (c - x[i]));
  }
  s = 0;
  for (long long i = 0; i < n; i++) {
    s += v[i];
    ans = max(ans, max(s - (x[i]), s - c));
    ans = max(ans, s - (2 * x[i]) + ma[i + 1]);
  }
  for (long long i = 0; i < 100000; i++) ma[i] = 0;
  s = 0;
  for (long long i = 0; i < n; i++) {
    s += v[i];
    if (i == 0)
      ma[i] = s - x[i];
    else
      ma[i] = max(ma[i - 1], s - x[i]);
  }
  s = 0;
  for (long long i = n - 1; i >= 1; i--) {
    s += v[i];
    ans = max(ans, max(s - (c - x[i]), s - c));
    ans = max(ans, s - (2 * (c - x[i])) + ma[i - 1]);
  }
  ans = max(ans, sum - c);
  cout << ans << endl;
  return 0;
}
