#include <bits/stdc++.h>
using namespace std;
long long n, c;
long long f[1000][1000][2];
long long ans;
struct food {
  long long x, v;
} a[100100];
long long read() {
  long long sum = 0;
  ;
  char c = getchar();
  while (c < '0' || c > '9') c = getchar();
  while (c >= '0' && c <= '9') sum = sum * 10 + c - 48, c = getchar();
  return sum;
}
void dfs(int l, int r, bool now, long long value) {
  if (value > f[l][r][now])
    f[l][r][now] = value;
  else
    return;
  ans = max(ans, value);
  if (l > r) return;
  if (now) {
    dfs(l + 1, r, 1, value + a[l].v - (a[l].x - a[l - 1].x));
    dfs(l, r - 1, 0, value + a[r].v - (a[l - 1].x + (c - a[r].x)));
  } else {
    dfs(l + 1, r, 1, value + a[l].v - ((c - a[r + 1].x) + a[l].x));
    dfs(l, r - 1, 0, value + a[r].v - (a[r + 1].x - a[r].x));
  }
  return;
}
void init() {
  n = read();
  c = read();
  for (int i = 1; i <= n; ++i) a[i].x = read(), a[i].v = read();
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= n; ++j) f[i][j][1] = f[i][j][0] = -1e15;
  dfs(2, n, 1, a[1].v - a[1].x);
  dfs(1, n - 1, 0, a[n].v - (c - a[n].x));
  printf("%lld", ans);
  return;
}
int main() {
  init();
  return 0;
}
