#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);
  vector<long long> bdy = vector<long long>(N + 1);
  vector<long long> brev = 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]);
    bdy[i] = point[i];
    if (result < dy[i]) {
      result = dy[i];
    }
  }
  rev[N] = value[N] - (C - point[N]);
  for (int i = N - 1; i >= 1; i--) {
    long long diff = point[i + 1] - point[i];
    rev[i] = rev[i + 1] + value[i] - diff;
    brev[i] = diff;
    if (result < rev[i]) {
      result = rev[i];
    }
  }
  for (int i = 1; i <= N; i++) {
    if (dy[i] < dy[i - 1]) {
      dy[i] = dy[i - 1];
      bdy[i] = bdy[i - 1];
    }
  }
  for (int i = N - 1; i >= 1; i--) {
    if (rev[i] < rev[i + 1]) {
      rev[i] = rev[i + 1];
      brev[i] = brev[i + 1];
    }
  }
  long long t_result = 0;
  int st = 0;
  for (int i = 1; i <= N; i++) {
    if (t_result < dy[i] + rev[i - 1] - (C - point[i - 1])) {
      t_result = dy[i] + rev[i - 1] - (C - point[i - 1]);
    }
    if (t_result < dy[i + 1] + rev[i] - point[i + 1]) {
      t_result = dy[i + 1] + rev[i] - point[i + 1];
    }
  }
  if (result < t_result) result = t_result;
  cout << result << endl;
  return 0;
  cout << result << endl;
  return 0;
}
