#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100010;
long long dist[MAXN];
long long nut[MAXN];
int main() {
  int n;
  cin >> n;
  long long c;
  cin >> c;
  vector<pair<long long, long long> > v(n + 1);
  for (int i = 1; i <= n; ++i) {
    cin >> v[i].first >> v[i].second;
  }
  for (int i = 1; i <= n; ++i) {
    dist[i] = v[i].first;
    nut[i] = nut[i - 1] + v[i].second;
  }
  long long best = 0;
  for (int i = 1; i <= n; ++i) {
    for (int j = n; j >= i; --j) {
      long long dist1 = c - dist[j];
      long long dist2 = dist[i];
      long long distt = 2 * min(dist1, dist2) + max(dist1, dist2);
      long long fud = nut[i] + nut[n] - nut[j - 1];
      long long p = fud - distt;
      best = max(best, p);
    }
  }
  cout << best;
  return 0;
}
