#include <bits/stdc++.h>
using namespace std;
int INF = (1LL << 30) - 1;
int MOD = 1e9 + 7;
int main() {
  long long N, C;
  cin >> N >> C;
  if (N > 100) exit(1);
  vector<long long> X(N), V(N);
  for (int i = int(0); i < int(N); ++i) cin >> X[i] >> V[i];
  long long maxi = 0;
  for (int i = int(0); i < int(N + 1); ++i)
    for (int j = int(0); j < int(N + 1); ++j) {
      if (i + j > N) continue;
      long long sum = 0, l, r;
      if (i == 0)
        l = 0;
      else
        l = C - X[N - i];
      if (j == 0)
        r = 0;
      else
        r = X[j - 1];
      for (int k = int(0); k < int(i); ++k) {
        sum += V[N - 1 - k];
      }
      for (int k = int(0); k < int(j); ++k) {
        sum += V[k];
      }
      long long dif = l + r + min(l, r);
      maxi = max(maxi, sum - dif);
    }
  cout << maxi << endl;
}
