#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, c, x[10001], v[10001];
  long long r[10001], l[10001], rb[10001], lb[10001];
  long long ri[10001], li[10001], rbi[10001], lbi[10001];
  long long m = 0;
  cin >> n >> c;
  for (int i = 0; i < n; i++) {
    cin >> x[i] >> v[i];
  }
  r[0] = v[0] - x[0];
  ri[0] = 0;
  rb[0] = r[0] - x[0];
  rbi[0] = 0;
  m = max(m, r[0]);
  for (int i = 1; i < n; i++) {
    r[i] = r[i - 1] + v[i] - x[i] + x[i - 1];
    ri[i] = r[i] > r[i - 1] ? i : ri[i - 1];
    rb[i] = r[i] - x[i];
    rbi[i] = rb[i] > rb[i - 1] ? i : rbi[i - 1];
    m = max(m, r[i]);
  }
  l[n - 1] = v[n - 1] - c + x[n - 1];
  li[n - 1] = n - 1;
  lb[n - 1] = l[n - 1] - c + x[n - 1];
  lbi[n - 1] = n - 1;
  m = max(m, l[n - 1]);
  for (int i = n - 2; i >= 0; i--) {
    l[i] = l[i + 1] + v[i] + x[i] - x[i + 1];
    li[i] = l[i] > l[i + 1] ? i : li[i + 1];
    lb[i] = l[i] - c + x[i];
    lbi[i] = lb[i] > lb[i + 1] ? i : lbi[i + 1];
    m = max(m, l[i]);
  }
  for (int i = 0; i < n - 1; i++) {
    m = max(m, rb[i] + l[li[i + 1]]);
  }
  for (int i = n - 1; i > 0; i--) {
    m = max(m, lb[i] + r[ri[i - 1]]);
  }
  cout << m << endl;
}
