#include <bits/stdc++.h>
int main() {
  size_t N;
  intmax_t C;
  scanf("%zu %jd", &N, &C);
  std::vector<intmax_t> x(N), v(N);
  for (size_t i = 0; i < N; ++i) {
    scanf("%jd %jd", &x[i], &v[i]);
  }
  std::vector<intmax_t> cw(N), ccw(N);
  intmax_t res = 0;
  {
    intmax_t cal = 0, cur_x = 0;
    for (size_t i = 0; i < N; ++i) {
      cal += v[i] - (x[i] - cur_x);
      cw[i] = cal;
      cur_x = x[i];
      res = std::max(res, cal);
    }
  }
  {
    intmax_t cal = 0, cur_x = C;
    for (size_t i = N; i--;) {
      cal += v[i] - (cur_x - x[i]);
      ccw[i] = cal;
      cur_x = x[i];
      res = std::max(res, cal);
    }
  }
  if (N <= 100) {
    {
      for (size_t i = 0; i < N; ++i) {
        intmax_t init = cw[i] - x[i], cur = init;
        for (size_t j = N; j-- > i + 1;) {
          cur = std::max(cur, init + ccw[j]);
        }
        res = std::max(res, cur);
      }
    }
    {
      for (size_t i = N; i--;) {
        intmax_t init = ccw[i] - (C - x[i]), cur = init;
        for (size_t j = 0; j < i; ++j) {
          cur = std::max(cur, init + cw[j]);
        }
        res = std::max(res, cur);
      }
    }
  }
  printf("%jd\n", res);
}
