#include <bits/stdc++.h>
using namespace std;
void solve();
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  solve();
}
const long long INF = (long long)1e18 + 7;
void solve() {
  long long n, c;
  cin >> n >> c;
  vector<pair<long long, long long>> a(n);
  for (long long i = 0; i < n; ++i) cin >> a[i].first >> a[i].second;
  long long res = 0;
  for (long long i = 0; i <= n; ++i) {
    for (long long j = n - i; j >= 0; --j) {
      long long nutr = 0;
      for (long long k = 0; k < i; ++k) nutr += a[k].second;
      for (long long k = 0; k < j; ++k) nutr += a[n - k - 1].second;
      long long walk = 0;
      if (i == 0 && j == 0)
        walk = 0;
      else if (i == 0)
        walk = c - a[n - j].first;
      else if (j == 0)
        walk = a[i - 1].first;
      else
        walk = a[i - 1].first + c - a[n - j].first +
               min(a[i - 1].first, c - a[n - j].first);
      res = max(res, nutr - walk);
    }
  }
  cout << res << '\n';
}
