#include <bits/stdc++.h>
using namespace std;
int dx[] = {-1, 0, 1, 0, 0}, dy[] = {0, 1, 0, -1, 0};
int main() {
  long long int n, c, x[100000], v[100000], t = 0, xs = 0, vs = 0, vsj = 0;
  cin >> n >> c;
  for (int i = 0; i < n; i++) {
    cin >> x[i];
    cin >> v[i];
  }
  for (int i = 0; i < n; i++) {
    xs += x[i];
    vs += v[i];
    if (vs - x[i] > t) {
      t = vs - x[i];
    }
  }
  vs = 0;
  for (int i = n - 1; i >= 0; i--) {
    xs = c - x[i];
    vs += v[i];
    if (vs - xs > t) {
      t = vs - xs;
    }
  }
  vs = 0;
  for (int i = 0; i < n; i++) {
    vs += v[i];
    vsj = vs;
    for (int j = n - 1; j >= i + 1; j--) {
      xs = c - x[j] + 2 * x[i];
      vsj += v[j];
      if (vsj - xs > t) {
        t = vsj - xs;
      }
    }
  }
  vs = 0;
  for (int i = n - 1; i >= 0; i--) {
    vs += v[i];
    vsj = vs;
    for (int j = 0; j <= i - 1; j++) {
      xs = 2 * (c - x[i]) + x[j];
      vsj += v[j];
      if (vsj - xs > t) {
        t = vsj - xs;
      }
    }
  }
  cout << t;
  return 0;
}
