#include <bits/stdc++.h>
using namespace std;
constexpr long MAX_N = 100000;
long x[MAX_N];
long v[MAX_N];
bool eaten[MAX_N];
long c;
long leftw[MAX_N];
long rightw[MAX_N];
long distance(long from, long index) {
  long d = labs(from - x[index]);
  if (d > c / 2) {
    return c - d;
  } else {
    return d;
  }
}
int main(void) {
  long n;
  cin >> n >> c;
  for (long i = 0; i < n; i++) {
    cin >> x[i] >> v[i];
  }
  long max_cal = 0;
  long left_imax = -1;
  long right_imax = -1;
  {
    long now_cal = 0;
    long pos = 0;
    for (long i = 0; i < n; i++) {
      now_cal -= x[i] - pos;
      now_cal += v[i];
      pos = x[i];
      leftw[i] = now_cal;
      if (now_cal > max_cal) {
        max_cal = now_cal;
        left_imax = i;
      }
    }
  }
  {
    long now_cal = 0;
    long pos = c;
    for (long i = n - 1; i >= 0; i--) {
      now_cal -= pos - x[i];
      now_cal += v[i];
      pos = x[i];
      rightw[i] = now_cal;
      if (now_cal > max_cal) {
        max_cal = now_cal;
        right_imax = i;
      }
    }
  }
  {
    for (long i = 0; i < n; i++) {
      for (long j = n - 1; j > i; j--) {
        long now_cal = leftw[i] - x[i] + rightw[j];
        max_cal = max(max_cal, now_cal);
      }
    }
    for (long i = n - 1; i >= 0; i--) {
      for (long j = 0; j < i; j++) {
        long now_cal = rightw[i] - (c - x[i]) + leftw[j];
        max_cal = max(max_cal, now_cal);
      }
    }
  }
  cout << max_cal << endl;
  return 0;
}
