#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
const long long MOD = 1e9 + 7;
double EPS = 1e-8;
template <typename T>
struct SegTree {
  vector<T> dat;
  int n;
  const T Default;
  SegTree(int n_, const T& def) : Default(def) { init(n_); }
  void init(int n_) {
    n = 1;
    while (n < n_) n *= 2;
    dat = vector<T>(2 * n - 1, Default);
  }
  T f(const T& a, const T& b) { return max(a, b); }
  void update(int k, const T& a) {
    k += n - 1;
    dat[k] = a;
    while (k > 0) {
      k = (k - 1) / 2;
      dat[k] = f(dat[k * 2 + 1], dat[k * 2 + 2]);
    }
  }
  T query(int a, int b, int k, int l, int r) {
    if (r <= a || b <= l) return Default;
    if (a <= l && r <= b) return dat[k];
    T vector<long long> = query(a, b, k * 2 + 1, l, (l + r) / 2);
    T vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
    return f(vector<long long>, vr);
  }
  T query(int a, int b) { return query(a, b, 0, 0, n); }
};
int main() {
  long long n, c;
  cin >> n >> c;
  vector<long long> x(n), v(n);
  for (int i = (0); i < (int)(n); i++) cin >> x[i] >> v[i];
  vector<long long> r, l, ll, rr;
  l.push_back(0);
  ll.push_back(0);
  l.push_back(v[0] - x[0]);
  ll.push_back(v[0] - x[0] * 2);
  for (int i = (1); i < (int)(n); i++) {
    l.push_back(l.back() + x[i - 1] - x[i] + v[i]);
    ll.push_back(ll.back() + x[i - 1] * 2 - x[i] * 2 + v[i]);
  }
  r.push_back(0);
  rr.push_back(0);
  r.push_back(v.back() - (c - x.back()));
  rr.push_back(v.back() - (c - x.back()) * 2);
  for (int i = (int)(n - 1 - 1); i >= (int)(0); i--) {
    r.push_back(r.back() + (c - x[i + 1]) - (c - x[i]) + v[i]);
    rr.push_back(rr.back() + (c - x[i + 1]) * 2 - (c - x[i]) * 2 + v[i]);
  }
  SegTree<long long> L(n + 10, -INF), LL(n + 10, -INF), R(n + 10, -INF),
      RR(n + 10, -INF);
  for (int i = (0); i < (int)(l.size()); i++) {
    L.update(i, l[i]);
    LL.update(i, ll[i]);
    R.update(i, r[i]);
    RR.update(i, rr[i]);
  }
  long long ans = -INF;
  for (int i = (0); i < (int)(n + 1); i++) {
    ans = max(ans, L.query(0, i + 1) + RR.query(0, n - i));
    ans = max(ans, R.query(0, i + 1) + LL.query(0, n - i));
  }
  cout << ans << endl;
  return 0;
}
