#include <bits/stdc++.h>
using namespace std;
int main() {
  long N;
  long long C;
  vector<pair<long, long> > data;
  long x, v;
  cin >> N >> C;
  data.push_back(make_pair((0), (0)));
  for (int i = 0; i < N; i++) {
    cin >> x >> v;
    data.push_back(make_pair((x), (v)));
  }
  N++;
  sort(data.begin(), data.end());
  long long ret = 0;
  long long sum, sum2;
  sum = 0;
  for (long i = 0; i < N; i++) {
    long x1 = data[i].first;
    long v1 = data[i].second;
    sum += v1;
    ret = max(ret, sum - x1);
    sum2 = sum;
    for (long j = N - 1; j > i; j--) {
      long x2 = data[j].first;
      long v2 = data[j].second;
      sum2 += v2;
      ret = max(ret, sum2 - min(2 * x1 + C - x2, x1 + 2 * (C - x2)));
    }
  }
  cout << ret << endl;
  return 0;
}
