#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int N;
  long long C;
  cin >> N >> C;
  vector<long long> point = vector<long long>(N + 1);
  vector<long long> value = vector<long long>(N + 1);
  for (int i = 1; i <= N; i++) {
    cin >> point[i] >> value[i];
  }
  vector<long long> dy = vector<long long>(N + 1);
  vector<long long> rev = vector<long long>(N + 1);
  long long result = 0;
  for (int i = 1; i <= N; i++) {
    dy[i] = dy[i - 1] + value[i] - (point[i] - point[i - 1]);
    if (result < dy[i]) {
      result = dy[i];
    }
  }
  for (int i = 1; i <= N; i++) {
    long long diff =
        (i == 1) ? C - point[N - i + 1] : point[N - i + 2] - point[N - i + 1];
    rev[i] = rev[i - 1] + value[N - i + 1] - diff;
    if (result < rev[i]) {
      result = rev[i];
    }
  }
  if (result <= 0) {
    cout << 0 << endl;
    return 0;
  }
  int st = 0;
  int j = (N > 1) ? 2 : 1;
  long long t_result = 0;
  for (int i = 1; i <= N; i++) {
    if (i + j > N) break;
    long long min = dy[i] + rev[j] - point[i];
    if (t_result < min) {
      t_result = min;
      st = i;
    }
  }
  int i = st;
  for (int j = 1; j <= N; j++) {
    if (i + j > N) break;
    long long min =
        (C - point[N - j + 1] > point[i]) ? point[i] : C - point[N - j + 1];
    if (result < dy[i] + rev[j] - min) {
      result = dy[i] + rev[j] - min;
      st = i;
    }
  }
  st = 0;
  i = (N > 1) ? 2 : 1;
  t_result = 0;
  for (int j = 1; j <= N; j++) {
    if (i + j > N) break;
    long long min = dy[i] + rev[j] - (C - point[N - j + 1]);
    if (t_result < min) {
      t_result = min;
      st = j;
    }
  }
  for (int i = 1, j = st; i <= N; i++) {
    if (i + j > N) break;
    long long min =
        (C - point[N - j + 1] > point[i]) ? point[i] : C - point[N - j + 1];
    if (result < dy[i] + rev[j] - min) {
      result = dy[i] + rev[j] - min;
      st = i;
    }
  }
  cout << result << endl;
  return 0;
}
