#include <bits/stdc++.h>
using namespace std;
int main() {
  long n, c, x[1000], v[1000], a[1000], b[1000], d[1000], e[1000], al,
      q[1000][1000], ans;
  cin >> n >> c;
  ans = 0;
  for (long long i = 0; i < n; i++) {
    cin >> x[i] >> v[i];
  }
  for (long long i = 0; i < n; i++) {
    al += v[i];
  }
  for (long long i = 0; i < n; i++) {
    a[i] = 0;
    for (long long j = 0; j < i + 1; j++) a[i] += v[j];
    a[i] -= 2 * x[i];
    b[i] = a[i] + x[i];
  }
  for (long long i = 0; i < n; i++) {
    d[i] = al;
    for (long long j = 0; j < i; j++) d[i] -= v[j];
    e[i] = d[i];
    d[i] -= 2 * c;
    d[i] += 2 * x[i];
    e[i] -= c;
    e[i] += x[i];
  }
  for (long long i = 0; i < n - 1; i++) {
    for (long long j = i + 1; j < n; j++) {
      if (a[i] + e[j] < b[i] + d[j])
        q[i][j] = b[i] + d[j];
      else
        q[i][j] = a[i] + e[j];
    }
  }
  for (long long i = 0; i < n - 1; i++) {
    for (long long j = i + 1; j < n; j++) {
      if (ans < q[i][j]) ans = q[i][j];
    }
  }
  for (long long i = 0; i < n; i++) {
    if (ans < b[i]) ans = b[i];
    if (ans < e[i]) ans = e[i];
  }
  printf("%ld", ans);
}
