#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
inline long long read1() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
using namespace std;
const int N = 100010;
int n;
long long C, x[N];
int v[N];
long long pre[N], suf[N], p_sum[N], s_sum[N];
long long val_p[N], val_s[N];
int main() {
  n = read();
  C = read1();
  long long ans1 = 0, ans2 = 0;
  for (int i = 1; i <= n; i++) x[i] = read(), v[i] = read();
  for (int i = 1; i <= n; i++) p_sum[i] = p_sum[i - 1] + v[i];
  for (int i = n; i >= 1; i--) s_sum[i] = s_sum[i + 1] + v[i];
  for (int i = 1; i <= n; i++) {
    val_p[i] = p_sum[i] - 2 * x[i];
    val_s[i] = s_sum[i] - C + x[i];
  }
  for (int i = 1; i <= n; i++) pre[i] = max(pre[i - 1], val_p[i]);
  for (int i = n; i >= 1; i--) suf[i] = max(suf[i + 1], val_s[i]);
  for (int i = 0; i <= n; i++) ans1 = max(ans1, pre[i] + suf[i + 1]);
  for (int i = 1; i <= n; i++) p_sum[i] = p_sum[i - 1] + v[i];
  for (int i = n; i >= 1; i--) s_sum[i] = s_sum[i + 1] + v[i];
  for (int i = 1; i <= n; i++) {
    val_p[i] = p_sum[i] - x[i];
    val_s[i] = s_sum[i] - 2 * (C - x[i]);
  }
  for (int i = 1; i <= n; i++) pre[i] = max(pre[i - 1], val_p[i]);
  for (int i = n; i >= 1; i--) suf[i] = max(suf[i + 1], val_s[i]);
  for (int i = 0; i <= n; i++) ans2 = max(ans2, pre[i] + suf[i + 1]);
  cout << max(ans1, ans2) << endl;
  return 0;
}
