#include <bits/stdc++.h>
using namespace std;
int main() {
  uint64_t N, C;
  cin >> N >> C;
  vector<pair<uint64_t, uint64_t> > sushi(N);
  for (uint64_t i = 0; i < N; i++) {
    cin >> sushi[i].first >> sushi[i].second;
  }
  uint64_t calall = 0;
  vector<pair<uint64_t, uint64_t> > wise(N + 1);
  vector<pair<uint64_t, uint64_t> > cwise(N + 1);
  wise[0] = cwise[0] = {0, 0};
  for (uint64_t i = 1; i < N + 1; i++) {
    wise[i] = {sushi[i - 1].first, wise[i - 1].second + sushi[i - 1].second};
    cwise[i] = {C - sushi[N - i].first,
                cwise[i - 1].second + sushi[N - i].second};
    calall += sushi[i - 1].second;
  }
  uint64_t calmax = 0;
  uint64_t i, j;
  for (i = 0; i < N + 1; i++) {
    if (calall <= wise[i].first) break;
    for (j = 0; i + j < N + 1; j++) {
      uint64_t cal = wise[i].second + cwise[j].second;
      uint64_t d = min(wise[i].first * 2 + cwise[j].first,
                       wise[i].first + cwise[j].first * 2);
      if (calall <= d) break;
      if (cal > d) {
        calmax = max(calmax, cal - d);
      }
    }
  }
  cout << calmax;
  return 0;
}
