#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
signed main() {
  long long n, c;
  cin >> n >> c;
  vector<long long> x(n);
  vector<long long> v(n);
  for (long long i = 0; i < n; i++) cin >> x[i] >> v[i];
  if (n == 1) {
    long long a = (v[0] + x[0] - c);
    long long b = v[0] - x[0];
    long long ans = 0;
    ans = max(ans, max(b, a));
    cout << ans << endl;
    return 0;
  }
  vector<pair<long long, long long> > bestr(n);
  long long np = v[0] - x[0];
  if (np <= 0) {
    bestr[0] = make_pair(0, 0);
  } else {
    bestr[0] = make_pair(np, x[0]);
  }
  for (long long i = 1; i < n; i++) {
    np += v[i];
    np -= abs(x[i - 1] - x[i]);
    if (np <= bestr[i - 1].first) {
      bestr[i] = bestr[i - 1];
    } else {
      bestr[i] = make_pair(np, x[i]);
    }
  }
  long long ans = bestr[n - 1].first;
  long long lp = v[n - 1];
  lp -= abs(c - x[n - 1]);
  long long dis = min(c - x[n - 1], bestr[n - 2].second);
  ans = max(ans, lp + bestr[n - 2].first - dis);
  for (long long i = n - 2; i > 0; i--) {
    lp += v[i];
    lp -= abs(x[i] - x[i + 1]);
    dis = min(c - x[i], bestr[i - 1].second);
    ans = max(ans, lp + bestr[i - 1].first - dis);
  }
  lp += v[0];
  lp -= abs(x[0] - x[1]);
  ans = max(ans, lp);
  cout << ans << endl;
}
