#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000009;
const long long INFLL = 0x1f1f1f1f1f1f1f1fLL;
template <class A, class B>
inline ostream& operator<<(ostream& st, const pair<A, B>& P) {
  return st << "(" << P.first << ", " << P.second << ")";
};
template <class A, class B>
inline pair<A, B> operator+(const pair<A, B>& P, const pair<A, B>& Q) {
  return pair<A, B>(P.first + Q.first, P.second + Q.second);
};
template <class A, class B>
inline pair<A, B> operator-(const pair<A, B>& P, const pair<A, B>& Q) {
  return pair<A, B>(P.first - Q.first, P.second - Q.second);
};
long long x[100005];
long long v[100005];
int main() {
  long long n, c;
  long long ret = 0;
  cin >> n >> c;
  if (n > 100) return 0;
  for (int i = 0; i < n; i++) {
    cin >> x[i] >> v[i];
  }
  for (int _ = 0; _ < 2; _++) {
    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++) {
        if (i + j >= n) continue;
        long long r = 0;
        if (i != 0) {
          for (int k = 0; k < i; k++) {
            r += v[k];
          }
          r -= x[i - 1] * 2;
        }
        for (int k = 0; k < j; k++) {
          r += v[n - k - 1];
        }
        r -= c - x[n - j];
        ret = max(ret, r);
      }
    for (int i = 0, j = n - 1; i < j; ++i, --j) {
      swap(x[i], x[j]);
      swap(v[i], v[j]);
    }
    for (int i = 0; i < n; i++) x[i] = c - x[i];
  }
  cout << ret << endl;
}
