#include <bits/stdc++.h>
using namespace std;
long long x[100005] = {0};
long long v[100005] = {0};
long long sum1[100005] = {0};
long long sum2[100005] = {0};
long long shun[100005] = {0};
long long ni[100005] = {0};
int main() {
  long long n, c;
  scanf("%lld%lld", &n, &c);
  for (int i = 1; i <= n; i++) {
    scanf("%lld%lld", &x[i], &v[i]);
    sum1[i] = sum1[i - 1] + v[i];
    shun[i] = max(shun[i - 1], sum1[i] - x[i]);
  }
  long long maxn = shun[n];
  for (int i = n; i > 0; i--) {
    sum2[i] = sum2[i + 1] + v[i];
    ni[i] = max(ni[i + 1], sum2[i] - c + x[i]);
  }
  maxn = max(maxn, ni[1]);
  for (int i = 1; i <= n; i++) {
    maxn = max(maxn, sum1[i] - 2 * x[i] + ni[i + 1]);
  }
  printf("%lld\n", maxn);
  return 0;
}
