#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
long long x[N], v[N], ans[N];
int main() {
  long long n, c;
  cin >> n >> c;
  for (int i = 1; i <= n; i++) cin >> x[i] >> v[i];
  long long res = 0, r = 0;
  for (long long i = n; i > 0; i--) {
    if (i == n)
      r -= (c - x[i]);
    else
      r -= (x[i + 1] - x[i]);
    r += v[i];
    ans[i] = max(ans[i + 1], r);
    res = max(res, ans[i]);
  }
  r = 0;
  for (long long i = 1; i <= n; i++) {
    if (i == n)
      r -= x[i];
    else
      r -= (x[i] - x[i - 1]);
    r += v[i];
    res = max(res, max(r, r + ans[i + 1] - x[i]));
    ans[i] = max(ans[i - 1], r);
  }
  r = 0;
  for (long long i = n; i > 0; i--) {
    if (i == n)
      r -= (c - x[i]);
    else
      r -= (x[i + 1] - x[i]);
    r += v[i];
    res = max(res, r + ans[i - 1] - (c - x[i]));
  }
  cout << res;
  return 0;
}
