#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  int64_t C;
  cin >> N >> C;
  vector<int64_t> x(N), v(N);
  vector<int64_t> x2(N), v2(N);
  for (int i = 0; i < N; ++i) {
    cin >> x[i] >> v[i];
    x2[i] = C - x[i];
    v2[i] = v[i];
  }
  v[0] -= x[0];
  int64_t ans = 0;
  ans = max(ans, v[0]);
  for (int i = 1; i < N; ++i) {
    v[i] += x[i - 1];
    v[i] -= x[i];
    v[i] += v[i - 1];
    ans = max(ans, v[i]);
  }
  v2[N - 1] -= x2[N - 1];
  ans = max(ans, v2[N - 1]);
  for (int i = N - 2; i >= 0; --i) {
    v2[i] += x2[i + 1];
    v2[i] -= x2[i];
    v2[i] += v2[i + 1];
    ans = max(ans, v2[i]);
  }
  for (int i = 0; i < N - 1; ++i) {
    for (int j = i + 1; j < N; ++j) {
      int64_t sum = v[i] - x[i] + v2[j];
      ans = max(ans, sum);
    }
  }
  for (int i = 0; i < N - 1; ++i) {
    for (int j = 0; j < i; ++j) {
      int64_t sum = v2[i] - x2[i] + v[j];
      ans = max(ans, sum);
    }
  }
  cout << ans << endl;
}
