#include <bits/stdc++.h>
using namespace std;
pair<long long, long long> x1[100001], x2[100001];
pair<long long, long long> p[100001];
long long v[100001];
int main() {
  int n;
  long long c;
  long long xi, vi;
  cin >> n >> c;
  for (int i = (0); i < (n); ++i) {
    cin >> xi >> vi;
    x1[i] = {xi, vi};
    x2[i] = {c - xi, vi};
    v[i] = vi;
  }
  sort(x1, x1 + n);
  sort(x2, x2 + n);
  long long mx = 0, sum = 0;
  long long pre = 0;
  long long tmpmx = 0, cur = -1;
  for (int i = (0); i < (n); ++i) {
    sum += x1[i].second - (x1[i].first - pre);
    mx = max(sum, mx);
    p[i] = {sum - x1[i].first, cur = c - x1[i].first};
    pre = x1[i].first;
  }
  for (int i = (0); i < (n); ++i) {
    sum = 0, pre = 0;
    for (int j = (0); j < (n); ++j) {
      if (x2[j].first == p[i].second) break;
      sum += x2[j].second - (x2[j].first - pre);
      mx = max(sum + p[i].first, mx);
      pre = x2[j].first;
    }
  }
  sum = 0;
  pre = 0;
  tmpmx = 0, cur = -1;
  for (int i = (0); i < (n); ++i) {
    sum += x2[i].second - (x2[i].first - pre);
    mx = max(sum, mx);
    p[i] = {sum - x2[i].first, cur = c - x2[i].first};
    pre = x2[i].first;
  }
  for (int i = (0); i < (n); ++i) {
    sum = 0, pre = 0;
    for (int j = (0); j < (n); ++j) {
      if (x1[j].first == p[i].second) break;
      sum += x1[j].second - (x1[j].first - pre);
      mx = max(sum + p[i].first, mx);
      pre = x1[j].first;
    }
  }
  cout << mx << endl;
  return 0;
}
