#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
const int INF = 1 << 28;
const double EPS = 1e-10;
long long n, c;
long long x[10005];
long long v[10005];
int main() {
  cin >> n >> c;
  for (int i = 0; i < n; i++) {
    cin >> x[i] >> v[i];
  }
  deque<int> q;
  for (int i = 0; i < n; i++) q.push_back(i);
  long long ans = 0;
  long long cur = 0;
  long long tot = 0;
  while (q.size()) {
    cout << tot << endl;
    if (q.size() > 1) {
      int fr = q.front();
      int bk = q.back();
      long long fr_v = 0;
      if (cur <= x[fr]) {
        fr_v = v[fr] - (x[fr] - cur);
      } else {
        fr_v = v[fr] - (x[fr] + c - cur);
      }
      long long bk_v = 0;
      if (cur >= x[bk]) {
        bk_v = v[bk] - (cur - x[bk]);
      } else {
        bk_v = v[bk] - (cur + c - x[bk]);
      }
      if (fr_v > bk_v) {
        tot += fr_v;
        cur = x[fr];
        q.pop_front();
      } else {
        tot += bk_v;
        cur = x[bk];
        q.pop_back();
      }
    } else {
      int fr = q.front();
      if (abs(cur - x[fr]) > (c - abs(cur - x[fr]))) {
        tot += (v[fr] - (c - abs(cur - x[fr])));
      } else {
        tot += (v[fr] - abs(cur - x[fr]));
      }
      q.pop_front();
    }
    ans = max(ans, tot);
  }
  cout << ans << endl;
  return 0;
}
