#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 55;
long long a[maxn], b[maxn];
long long x[maxn], v[maxn];
long long sum[maxn];
int main() {
  long long n, c;
  cin >> n >> c;
  for (int i = 1; i <= n; i++) cin >> x[i] >> v[i];
  for (long long i = 1; i <= n; i++) a[i] = a[i - 1] + v[i] - (x[i] - x[i - 1]);
  x[n + 1] = c;
  for (long long i = n; i >= 1; i--) b[i] = b[i + 1] + v[i] - (x[i + 1] - x[i]);
  for (long long i = 2; i <= n; i++) a[i] = max(a[i - 1], a[i]);
  for (long long i = n - 1; i >= 1; i--) b[i] = max(b[i], b[i + 1]);
  long long ans = 0;
  for (long long i = 0; i <= n; i++) {
    ans = max(ans, -x[i] + a[i] + b[i + 1]);
    ans = max(ans, -(c - x[i]) + b[i] + a[i - 1]);
  }
  cout << ans << endl;
}
