#include <bits/stdc++.h>
using namespace std;
template <typename T>
bool chkmax(T& a, T b) {
  return a < b ? a = b, 1 : 0;
}
template <typename T>
bool chkmin(T& a, T b) {
  return a > b ? a = b, 1 : 0;
}
const int maxn = 100000 + 100;
const long long inf = 1e15;
int n;
long long m, ans = -inf;
long long dis[maxn], val[maxn], pre_val[maxn], suf_val[maxn];
inline void read(long long& x) {
  x = 0;
  long long p = 1;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-') p = -1;
    c = getchar();
  }
  while (isdigit(c)) {
    x = (x << 1) + (x << 3) + (c - '0');
    c = getchar();
  }
  x *= p;
}
inline void file() {
  freopen("D.in", "r", stdin);
  freopen("D.out", "w", stdout);
}
int main() {
  scanf("%d", &n);
  read(m);
  for (int i = 1; i <= n; ++i) {
    read(dis[i]);
    read(val[i]);
    pre_val[i] = suf_val[i] = val[i];
  }
  for (int i = 1; i <= n; ++i) pre_val[i] += pre_val[i - 1];
  for (int i = n; i >= 1; --i) suf_val[i] += suf_val[i + 1];
  for (int i = 1; i <= n; ++i) {
    long long s = 0, p = n + 1;
    for (int j = i + 1; j <= n; ++j)
      if (chkmax(s, suf_val[j] - (m - dis[j]) * 2)) p = j;
    s += pre_val[i] - dis[i];
    chkmax(ans, s);
    for (int j = i + 1; j <= p - 1; ++j) {
      s += val[j] - (dis[j] - dis[j - 1]);
      chkmax(ans, s);
    }
  }
  for (int i = n; i >= 1; --i) {
    long long s = 0, p = 0;
    for (int j = 1; j <= i - 1; ++j)
      if (chkmax(s, pre_val[j] - dis[j] * 2)) p = j;
    s += suf_val[i] - (m - dis[i]);
    chkmax(ans, s);
    for (int j = i - 1; j >= p + 1; --j) {
      s += val[j] - (dis[j + 1] - dis[j]);
      chkmax(ans, s);
    }
  }
  printf("%lld\n", max(ans, 0ll));
  return 0;
}
