#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  long long C;
  cin >> C;
  vector<long long> x(N), v(N);
  for (int(i) = 0; (i) < (N); (i)++) {
    cin >> x[i] >> v[i];
  }
  vector<long long> sum(N + 1), sumr(N + 1);
  for (int i = 0; i < N; i++) sum[i + 1] = sum[i] + v[i];
  for (int i = N; i > 0; i--) sumr[i - 1] = sumr[i] + v[i - 1];
  for (int(i) = (1); (i) < (N + 1); (i)++) sum[i] -= x[i - 1];
  for (int(i) = 0; (i) < (N); (i)++) sumr[i] -= C - x[i];
  vector<long long> best(N + 1), bestr(N + 1);
  for (int i = 0; i < N; i++) {
    best[i + 1] = max(sum[i + 1], best[i]);
  }
  for (int i = N; i > 0; i--) {
    bestr[i - 1] = max(sumr[i - 1], bestr[i]);
  }
  long long res = 0;
  for (int(i) = (1); (i) < (N + 1); (i)++) {
    res = max(sum[i], res);
    if (i != N) res = max(res, sum[i] - x[i - 1] + bestr[i + 1]);
  }
  for (int(i) = 0; (i) < (N); (i)++) {
    res = max(sumr[i], res);
    if (i != 0) res = max(res, sumr[i] - (C - x[i]) + best[i]);
  }
  cout << res << endl;
  return 0;
}
