#include <bits/stdc++.h>
using namespace std;
int dx[8] = {0, 0, -1, 1, 1, 1, -1, -1};
int dy[8] = {-1, 1, 0, 0, 1, -1, 1, -1};
const int SIZE = 100050;
int main() {
  long long N, C;
  cin >> N >> C;
  if (N > 100) return 0;
  vector<pair<long long, long long> > A, B;
  A.push_back(make_pair(0, 0));
  B.push_back(make_pair(0, 0));
  for (int i = 0; i < N; i++) {
    long long x, v;
    cin >> x >> v;
    A.push_back(make_pair(x, v));
    B.push_back(make_pair(C - x, v));
  }
  sort(A.begin(), A.end());
  sort(B.begin(), B.end());
  for (int i = 1; i < N; i++) {
    A[i].second += A[i - 1].second;
    B[i].second += B[i - 1].second;
  }
  long long maxi = 0;
  for (int i = 0; i < N; i++) {
    maxi = max(maxi, A[i].second - A[i].first);
    maxi = max(maxi, B[i].second - B[i].first);
  }
  for (int i = 0; i <= N; i++) {
    for (int j = 0; j <= N - i; j++) {
      long long temp = 0;
      temp += A[i].second - A[i].first;
      temp += B[j].second - B[j].first;
      temp -= min(A[i].first, B[j].first);
      maxi = max(temp, maxi);
    }
  }
  cout << maxi << endl;
  return 0;
}
