#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long N, C;
  long long Ans = 0, sum = 0, sum2 = 0;
  long long x[114514];
  long long v[114514];
  long long w[114514] = {};
  cin >> N >> C;
  for (long long i = 0; i < (N); i++) {
    cin >> x[i] >> v[i];
    w[i + 1] = w[i] + v[i];
  }
  for (long long i = 0; i < (N); i++) {
    Ans = max(Ans, w[i + 1] - x[i]);
  }
  for (long long i = 0; i < (N); i++) {
    Ans = max(Ans, w[N] - w[i] - C + x[i]);
  }
  for (long long j = 0; j < (N); j++) {
    for (long long i = 0; i < (j); i++) {
      sum = 0, sum2 = 0;
      sum += w[i + 1];
      sum += w[N] - w[j];
      sum2 += x[i];
      sum2 += C - x[j];
      sum2 += min(x[i], C - x[j]);
      Ans = max(Ans, sum - sum2);
    }
  }
  cout << Ans << endl;
  return 0;
}
