#include <bits/stdc++.h>
using namespace std;
long long C, N, x[100050], v[100050], ni[100050], shun[100050], ans;
int main() {
  while (cin >> N >> C) {
    ans = 0;
    memset(shun, 0, sizeof(shun));
    memset(ni, 0, sizeof(ni));
    for (int i = 1; i <= N; i++) {
      scanf("%lld %lld", &x[i], &v[i]);
    }
    shun[1] = v[1] - x[1];
    for (int i = 1; i <= N; i++) {
      shun[i] = max(shun[i - 1], shun[i - 1] + (v[i] - x[i]) + x[i - 1]);
    }
    ni[N] = v[N] - (C - x[N]);
    for (int i = N - 1; i >= 1; i--) {
      ni[i] = max(ni[i + 1], ni[i + 1] + v[i] - (C - x[i]) + (C - x[i + 1]));
    }
    for (int i = 0; i <= N; i++) {
      ans = max(ans, shun[i] + ni[i + 1] - min(x[i], C - x[i]));
      if (i == 0 || i == N) ans = max(ans, shun[i] + ni[i + 1]);
    }
    cout << ans << endl;
  }
}
