#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];
    if (i > 0) {
      i_made[i] = i_made[i - 1] + v[i];
    } else {
      i_made[0] = v[0];
    }
  }
  long long tmp_v_sum = v_sum;
  for (int i = N - 1; i >= 0; i--) {
    res = max(res, tmp_v_sum - x[i]);
    tmp_v_sum -= v[i];
  }
  tmp_v_sum = v_sum;
  for (int i = 0; i < N; i++) {
    res = max(res, tmp_v_sum - (C - x[i]));
    tmp_v_sum -= v[i];
  }
  long long over = distance(x, lower_bound(x, x + N, C / 2));
  for (int i = 0; i < N; i++) {
    long long cost = 0;
    tmp_v_sum = 0;
    if (x[i] <= C / 4) {
      cost = x[i] * 2;
      tmp_v_sum = v_sum - i_made[over - 1] + i_made[i] - cost;
      for (int i = over; i < N; i++) {
        res = max(res, tmp_v_sum - (C - x[i]));
        tmp_v_sum -= v[i];
      }
    }
  }
  for (int i = 0; i < N; i++) {
    long long cost = 0;
    tmp_v_sum = 0;
    if (x[i] >= 3 * C / 4) {
      cost = (C - x[i]) * 2;
      tmp_v_sum = i_made[over - 1] + (v_sum - i_made[i - 1]) - cost;
      for (int i = over - 1; i >= 0; i--) {
        res = max(res, tmp_v_sum - x[i]);
        tmp_v_sum -= v[i];
      }
    }
  }
  cout << res << endl;
  return 0;
}
