#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const long long INFLL = 1e18;
int dx[4] = {0, -1, 1, 0}, dy[4] = {-1, 0, 0, 1};
int main() {
  ios::sync_with_stdio(false);
  int N;
  long long C;
  cin >> N >> C;
  vector<pair<long long, long long> > sushi(N);
  map<int, pair<long long, long long> > sushi_l, sushi_r;
  for (int i = 0; i < (int)(N); i++) {
    cin >> sushi[i].first >> sushi[i].second;
  }
  assert(N <= 100);
  sushi_l[0] = pair<long long, long long>(C, 0);
  sushi_r[0] = pair<long long, long long>(0, 0);
  for (int i = 0; i < (int)(N); i++) {
    sushi_l[(i + 1)] = sushi[N - i - 1];
    sushi_r[(i + 1)] = sushi[i];
  }
  long long ans = 0LL;
  long long suml = 0LL;
  for (int l = 0; l <= N; l++) {
    suml += sushi_l[l].second;
    long long sumr = 0LL;
    for (int r = 0; r <= N; r++) {
      sumr += sushi_r[r].second;
      if (sushi_l[l].first <= sushi_r[r].first) continue;
      long long cost = min(2 * (C - sushi_l[l].first) + sushi_r[r].first,
                           2 * sushi_r[r].first + (C - sushi_l[l].first));
      ans = max(ans, suml + sumr - cost);
      cerr << "("
           << "l"
           << ", "
           << "r"
           << ") = (" << l << ", " << r << ")" << endl;
      cerr << "ans"
           << "=" << ans << endl;
    }
  }
  cout << ans << endl;
}
