#include <bits/stdc++.h>
using namespace std;
struct Sushi {
  long long pos;
  long long nut;
};
const int maxn = 100005;
int N;
long long C;
Sushi A[maxn], B[maxn];
long long pfxA[maxn], pfxB[maxn];
int main() {
  cin >> N >> C;
  for (int i = 1; i <= N; i++) {
    long long xi, vi;
    cin >> xi >> vi;
    A[i] = {xi, vi};
    B[i] = {xi, vi};
  }
  B[N + 1] = {C, 0};
  for (int i = 1; i <= N; i++) {
    pfxA[i] = pfxA[i - 1] + A[i].nut;
    pfxB[N - i + 1] = pfxB[N - i + 2] + B[N - i + 1].nut;
  }
  long long ans = 0;
  for (int i = 0; i <= N; i++) {
    for (int j = N + 1; j > i; j--) {
      long long OA = A[i].pos, OB = C - B[j].pos;
      long long d = OA + OB + min(OA, OB);
      long long nut = pfxA[i] + pfxB[j];
      long long T = nut - d;
      ans = max(ans, T);
    }
  }
  cout << ans << '\n';
  return 0;
}
