#include <bits/stdc++.h>
using namespace std;
struct edge {
  long long to, cost;
};
long long x[114514], v[114514];
long long rwa[114514];
signed main() {
  long long n, c;
  cin >> n >> c;
  for (long long i = 0; i < n; i++) {
    cin >> x[i] >> v[i];
  }
  long long ans = 0;
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < n; j++) {
      long long sum = 0;
      long long J;
      if (i <= j)
        J = j;
      else
        J = j + n;
      for (long long k = i; k <= J; k++) {
        sum += v[k % n];
      }
      long long d = 0;
      if (i <= j) {
        d = min(x[j], c - x[i]);
      } else {
        d = c - x[i] + x[j];
        d += min(x[j], c - x[i]);
      }
      sum -= d;
      ans = max(ans, sum);
    }
  }
  cout << ans << endl;
}
