#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N, C;
  cin >> N >> C;
  long long x[100000], v[100000];
  long long i_made[100000];
  long long v_sum = 0;
  long long res = 0;
  for (int i = 0; i < N; i++) {
    cin >> x[i] >> v[i];
    v_sum += v[i];
    i_made[i] = v_sum;
  }
  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      long long cost = min(C - x[j] + x[i] * 2, (C - x[j]) * 2 + x[i]);
      long long score = i_made[i] + v_sum - i_made[j - 1];
      res = max(res, score - cost);
    }
    for (int i = 0; i < N; i++) {
      res = max(res, i_made[i] - x[i]);
    }
  }
  cout << res << endl;
  return 0;
}
