#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using namespace std;
template <class T>
void vin(vector<T>& v, int n) {
  v.resize(n);
  for (int i = 0; i < n; ++i) {
    cin >> v[i];
  }
}
ll N, C;
vector<pair<ll, ll>> p;
int main() {
  cin >> N >> C;
  for (int(i) = (0); (i) < (int)(N); ++(i)) {
    ll x, v;
    cin >> x >> v;
    p.emplace_back(x, v);
  }
  sort(p.begin(), p.end());
  ll ans = 0, tmp = 0, pos = 0;
  for (int i = 0; i < N; ++i) {
    tmp += p[i].second - (p[i].first - pos);
    ans = max(ans, tmp);
    pos = p[i].first;
    ll ma = 0, tmp2 = 0, pos2 = 0;
    tmp2 = -pos;
    pos2 = C;
    for (int j = N - 1; j > i; --j) {
      tmp2 += p[j].second - (pos2 - p[j].first);
      pos2 = p[j].first;
      ma = max(ma, tmp + tmp2);
    }
    ans = max(ans, ma);
  }
  pos = C;
  tmp = 0;
  for (int i = N - 1; i >= 0; --i) {
    tmp += p[i].second - (pos - p[i].first);
    pos = p[i].first;
    ans = max(ans, tmp);
    ll ma = 0, tmp2 = -(C - pos), pos2 = 0;
    for (int j = 0; j < i; ++j) {
      tmp2 += p[j].second - (p[j].first - pos2);
      pos2 = p[j].first;
      ma = max(ma, tmp + tmp2);
    }
    ans = max(ans, ma);
  }
  cout << ans << endl;
}
