#include <bits/stdc++.h>
template <typename T>
inline void check_max(T a, T &b) {
  if (a > b) b = a;
}
namespace o_o {
const int N = 1010;
long long x[N], w[N];
int n;
long long m;
long long calc(int u, int v) {
  long long ret = w[u] + (w[n] - w[v - 1]);
  long long a = x[u], b = m - x[v], c = std::min(a, b);
  ret -= a + b + c;
  return ret;
}
void solve() {
  scanf("%d%lld", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%lld%lld", x + i, w + i);
  for (int i = 1; i <= n; i++) w[i] += w[i - 1];
  long long ans = 0;
  for (int i = 1; i <= n; i++)
    for (int j = i + 1; j <= n; j++) check_max(calc(i, j), ans);
  for (int i = 1; i <= n; i++) check_max(w[i] - x[i], ans);
  for (int i = 1; i <= n; i++) check_max(w[n] - w[i - 1] - (m - w[i]), ans);
  printf("%lld\n", ans);
}
}  // namespace o_o
int main() {
  o_o::solve();
  return 0;
}
