#include <bits/stdc++.h>
using namespace std;
pair<long long, long long> xv[100001];
deque<pair<long long, long long> > dq;
bool cmp_f(pair<long long, long long> p1, pair<long long, long long> p2) {
  return p1.first < p2.first;
}
int main(void) {
  long long N, C, x, v, ans = 0;
  scanf("%lld%lld", &N, &C);
  for (int i = 0; i < N; i++) {
    scanf("%lld%lld", &x, &v);
    xv[i] = make_pair(x, v);
  }
  sort(xv, xv + N, cmp_f);
  for (int i = 0; i < N; i++) dq.push_back(xv[i]);
  long long p = 0, now = 0, rest = N, gf, gb;
  bool fb;
  gf = dq.front().second - dq.front().first;
  gb = dq.back().second - (C - dq.back().first);
  if (gf >= gb) {
    now += gf;
    p = dq.front().first;
    dq.pop_front();
    fb = true;
  } else {
    now += gb;
    p = dq.back().first;
    dq.pop_back();
    fb = false;
  }
  ans = max(ans, now);
  rest--;
  while (rest > 0) {
    long long xt, vt;
    if (rest == 1) {
      xt = dq.front().first;
      vt = dq.front().second;
      dq.pop_front();
      now += vt - min(abs(p - xt), abs(C - abs(p - xt)));
    } else if (fb) {
      gf = dq.front().second - abs(dq.front().first - p);
      gb = dq.back().second - abs(C - abs(dq.back().first - p));
      if (gf >= gb) {
        now += gf;
        p = dq.front().first;
        dq.pop_front();
      } else {
        now += gb;
        p = dq.back().first;
        dq.pop_back();
        fb = false;
      }
    } else {
      gf = dq.front().second - abs(C - abs(dq.front().first - p));
      gb = dq.back().second - abs(dq.back().first - p);
      if (gf >= gb) {
        now += gf;
        p = dq.front().first;
        dq.pop_front();
        fb = true;
      } else {
        now += gb;
        p = dq.back().first;
        dq.pop_back();
      }
    }
    ans = max(ans, now);
    rest--;
  }
  return !printf("%lld\n", ans);
}
