#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int INF = 2e9;
long long N, C, ans = 0;
vector<pair<long long, long long> > xv, rev_xv;
vector<long long> c_sum, rev_c_sum;
int main() {
  cin >> N >> C;
  xv.push_back(make_pair(0, 0));
  for (int i = 0; i < N; i++) {
    long long x, v;
    cin >> x >> v;
    xv.push_back(make_pair(x, v));
  }
  xv.push_back(make_pair(0, 0));
  N += 2;
  rev_xv = xv;
  reverse(rev_xv.begin(), rev_xv.end());
  for (int i = 1; i < N - 1; i++) {
    rev_xv[i].first = C - rev_xv[i].first;
  }
  c_sum.push_back(xv[0].second);
  rev_c_sum.push_back(rev_xv[0].second);
  for (int i = 1; i < N; i++) {
    c_sum.push_back(c_sum[i - 1] + xv[i].second);
    rev_c_sum.push_back(rev_c_sum[i - 1] + rev_xv[i].second);
  }
  for (int l = 0; l < N; l++) {
    int r = N - l - 2;
    for (int lp = 0; lp <= l; lp++) {
      for (int rp = 0; rp <= r; rp++) {
        ans = max(ans, c_sum[lp] + rev_c_sum[rp] -
                           (xv[lp].first + rev_xv[rp].first +
                            min(xv[lp].first, rev_xv[rp].first)));
      }
    }
  }
  cout << ans << endl;
  return 0;
}
