#include <bits/stdc++.h>
using namespace std;
long long int n, c, x[100005], v[100005];
long long int ma[100005], mb[100005], a[100005], b[100005], ans, aonly[100005],
    ao, bonly[100005], bo;
long long int ansab, ansba, oa[100005], ob[100005], ansao, ansbo;
int main() {
  cin >> n >> c;
  for (long long int i = (long long int)0; i < (long long int)n; i++) {
    cin >> x[i] >> v[i];
    if (i > 0) {
      a[i] = a[i - 1] + 2 * x[i - 1] + v[i] - 2 * x[i];
      oa[i] = oa[i - 1] + x[i - 1] + v[i] - x[i];
      if (ma[i - 1] < a[i]) {
        ma[i] = a[i];
      } else {
        ma[i] = ma[i - 1];
      }
      if (aonly[i - 1] < oa[i]) {
        aonly[i] = oa[i];
      } else {
        aonly[i] = aonly[i - 1];
      }
    } else {
      a[i] = v[i] - 2 * x[i];
      oa[i] = v[i] - x[i];
      if (a[i] > 0) {
        ma[i] = a[i];
      }
      if (oa[i] > 0) {
        aonly[i] = oa[i];
      }
    }
  }
  for (long long int i = n - 1; i >= 0; i--) {
    if (i < n - 1) {
      b[i] = b[i + 1] + 2 * (c - x[i + 1]) + v[i] - 2 * (c - x[i]);
      ob[i] = ob[i + 1] + (c - x[i + 1]) + v[i] - (c - x[i]);
      if (mb[i + 1] < b[i]) {
        mb[i] = b[i];
      } else {
        mb[i] = mb[i + 1];
      }
      if (bonly[i + 1] < ob[i]) {
        bonly[i] = ob[i];
      } else {
        bonly[i] = bonly[i - 1];
      }
    } else {
      b[i] = v[i] - 2 * (c - x[i]);
      ob[i] = v[i] - (c - x[i]);
      if (b[i] > 0) {
        mb[i] = b[i];
      }
      if (ob[i] > 0) {
        bonly[i] = ob[i];
      }
    }
  }
  for (long long int i = (long long int)0; i < (long long int)n - 1; i++) {
    ansab = ansab < ma[i] + bonly[i + 1] ? ma[i] + bonly[i + 1] : ansab;
    ansao = ansao < aonly[i] ? aonly[i] : ansao;
  }
  for (long long int i = n - 1; i > 0; i--) {
    ansba = ansba < mb[i] + aonly[i - 1] ? mb[i] + aonly[i - 1] : ansba;
    ansbo = ansbo < bonly[i] ? bonly[i] : ansbo;
  }
  ans = ansab < ansba ? ansba : ansab;
  ans = ans < ansao ? ansao : ans;
  ans = ans < ansbo ? ansbo : ans;
  cout << ans << endl;
  return 0;
}
