#include <bits/stdc++.h>
using namespace std;
long long n, c, s, ans, x[10000], cal[10000], mx[10000], mx2[10000];
int main() {
  long long i;
  cin >> n >> c;
  for (i = 0; i < 10000; i++) {
    scanf("%lld %lld", &x[i], &cal[i]);
  }
  for (i = n - 1; i >= 0; i--) {
    s += cal[i];
    mx[i] = max(mx[i + 1], s - (c - x[i]));
    mx2[i] = max(mx2[i + 1], s - (c - x[i]) * 2);
  }
  ans = max(mx[0], mx2[0]);
  s = 0;
  for (i = 0; i < n; i++) {
    s += cal[i];
    ans = max(ans, s - x[i] * 2 + mx[i + 1]);
    ans = max(ans, s - x[i] + mx2[i + 1]);
  }
  cout << ans << endl;
  return 0;
}
