#include <bits/stdc++.h>
using namespace std;
long long min(long long a, long long b) { return (a < b) ? a : b; }
int main() {
  long long N;
  long long C;
  cin >> N >> C;
  long long x[100010];
  long long v[100010];
  long long sum = 0;
  for (int i = 0; i < N; i++) {
    cin >> x[i] >> v[i];
    sum += v[i];
  }
  long long cal = 0;
  long long max = 0;
  int dist = 0;
  for (int i = 0; i < N; i++) {
    cal += v[i];
    if (cal - x[i] > max) max = cal - x[i];
  }
  cal = 0;
  for (int i = 0; i < N; i++) {
    cal += v[N - 1 - i];
    if (cal - (C - x[N - 1 - i]) > max) max = cal - x[N - 1 - i];
  }
  long long cala = 0;
  long long calb = 0;
  for (int i = 0; i < N; i++) {
    if (x[i] > C / 2) break;
    cala += v[i];
    calb = 0;
    for (int j = 0; j < N; j++) {
      if (x[N - j - 1] <= x[i]) break;
      calb += v[N - j - 1];
      if (cala + calb - min(x[i], C - x[N - j - 1]) - x[i] -
              (C - x[N - j - 1]) >
          max) {
        max = cala + calb - min(x[i], C - x[N - j - 1]) - x[i] -
              (C - x[N - j - 1]);
      }
    }
  }
  cout << max;
  return 0;
}
