#include <bits/stdc++.h>
using namespace std;
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}
template <class T>
inline T sqr(T x) {
  return x * x;
}
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const long long MOD = (long long)1000000007;
const long long INF2 = (long long)100000000000000000;
int main() {
  long long n, c;
  cin >> n >> c;
  vector<long long> x(n + 2);
  vector<long long> v(n + 2);
  for (int i = 1; i < n + 1; i++) {
    cin >> x[i] >> v[i];
  }
  x[0] = 0;
  v[0] = 0;
  x[n + 1] = c;
  v[n + 1] = 0;
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = n + 1; j >= 0; j--) {
      if (i >= j) break;
      long long sumv = 0;
      for (int k = 0; k <= i; k++) {
        sumv += v[k];
      }
      for (int k = n + 1; k >= j; k--) {
        sumv += v[k];
      }
      long long la = x[i];
      long long lb = c - x[j];
      long long l = la + lb + min(la, lb);
      long long tmp = sumv - l;
      ans = max(ans, tmp);
    }
  }
  cout << ans << endl;
  return 0;
}
