#include <bits/stdc++.h>
using namespace std;
using I = long long;
int main() {
  I N, C;
  cin >> N >> C;
  vector<I> x(N), c(N);
  for (auto i = 0; i < N; ++i) cin >> x[i] >> c[i];
  vector<I> X;
  for (auto i : x) X.emplace_back(i - C);
  for (auto i : x) X.emplace_back(i);
  vector<I> D = c;
  for (auto i : c) D.emplace_back(i);
  I res = 0;
  for (auto l = 0; l < X.size(); ++l) {
    for (auto r = l; r < X.size(); ++r) {
      if (l + N == r) break;
      I sum = 0;
      for (auto i = l; i <= r; ++i) sum += D[i];
      if (X[l] < 0 && X[r] < 0) {
        sum -= -X[l];
      } else if (X[l] < 0) {
        sum -= min(-X[l], X[r]);
        sum -= X[r] - X[l];
      } else {
        sum -= X[r];
      }
      res = max(res, sum);
    }
  }
  cout << res << endl;
}
