#include <bits/stdc++.h>
using namespace std;
struct sushi {
  unsigned long long x, v;
};
int main() {
  unsigned long long n, c;
  cin >> n >> c;
  vector<sushi> s(n);
  for (int i = 0; i < n; i++) {
    sushi tmp;
    cin >> tmp.x >> tmp.v;
    s[i] = tmp;
  }
  sort(s.begin(), s.end(),
       [](sushi& a, sushi& b) -> bool { return a.x < b.x; });
  long long l_nut = 0, r_nut = 0, lpos = 0, rpos = c;
  int i;
  for (i = 0; i < n; i++) {
    if (s[i].x > c / 2) {
      break;
    }
    l_nut += s[i].v;
  }
  lpos = s[i - 1].x;
  rpos = s[i].x;
  for (; i < n; i++) {
    r_nut += s[i].v;
  }
  l_nut -= lpos;
  r_nut -= (c - rpos);
  long long maxnut = l_nut - (rpos - lpos) + r_nut + (c - s[n - 1].x);
  maxnut = maxnut < (l_nut + r_nut - lpos) ? l_nut + r_nut - lpos : maxnut;
  maxnut = maxnut < l_nut ? l_nut : maxnut;
  maxnut = maxnut < r_nut ? r_nut : maxnut;
  maxnut = maxnut < 0 ? 0 : maxnut;
  cout << maxnut << endl;
  return 0;
}
