#include <bits/stdc++.h>
using namespace std;
long long x[100005] = {0}, v[100005] = {0};
long long a[100005] = {0}, b[100005] = {0}, c[100005] = {0}, d[100005] = {0};
int main() {
  long long n, C;
  cin >> n >> C;
  for (long long i = 1; i <= n; i++) {
    scanf("%lld %lld", &x[i], &v[i]);
  }
  for (long long i = 1; i <= n; i++) {
    a[i] = a[i - 1] + v[i] - (x[i] - x[i - 1]);
  }
  for (long long i = 2; i <= n; i++) {
    a[i + 1] = max(a[i - 1], a[i]);
  }
  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 = n - 1; i >= 1; i--) {
    b[i] = max(b[i], b[i + 1]);
  }
  for (long long i = 1; i <= n; i++) {
    c[i] = a[i] - x[i] + b[i + 1];
  }
  for (long long i = 1; i <= n; i++) {
    d[i] = b[i] - (C - x[i]) + a[i - 1];
  }
  long long ans = 0;
  for (long long i = 1; i <= n; i++) {
    ans = max(ans, a[i] - x[i] + b[i + 1]);
    ans = max(ans, b[i] - (C - x[i]) + a[i - 1]);
    ans = max(ans, a[i]);
    ans = max(ans, b[i]);
  }
  cout << ans << endl;
}
