#include <bits/stdc++.h>
typedef struct {
  long long x;
  long long v;
} sushi;
int main() {
  long long n, c;
  std::cin >> n >> c;
  std::vector<sushi> vec;
  for (long long i = 0; i < n; i++) {
    sushi t;
    std::cin >> t.x >> t.v;
    vec.push_back(t);
  }
  long long* rinc = new long long[n + 1];
  rinc[0] = 0;
  long long* linc = new long long[n + 1];
  linc[0] = 0;
  for (long long i = 0; i < n; i++) {
    rinc[i + 1] = rinc[i] + vec[i].v;
  }
  for (long long i = 0; i < n; i++) {
    linc[i + 1] = linc[i] + vec[n - 1 - i].v;
  }
  long long score = 0;
  for (long long b = 0; b <= n; b++) {
    for (long long a = 0; a <= n - b; a++) {
      long long ax, bx;
      if (b == 0)
        bx = 0;
      else
        bx = c - vec[n - b].x;
      if (a == 0)
        ax = 0;
      else
        ax = vec[a - 1].x;
      long long tempA = rinc[a] + linc[b] - (2 * ax + bx);
      long long tempB = rinc[a] + linc[b] - (ax + 2 * bx);
      long long temp = (tempA > tempB) ? tempA : tempB;
      score = (score < temp) ? temp : score;
    }
  }
  std::cout << score << std::endl;
  delete[] rinc;
  delete[] linc;
  return 0;
}
