#include <bits/stdc++.h>
using namespace std;
const double PI = 2 * acos(0.0);
template <class T>
void show(const vector<T> &a) {
  for (T x : a) cout << x << " ";
  cout << endl;
}
const long long N = 2e5 + 9;
const long long oo = 1e18;
long long t[N << 2];
long long pushing[N << 2];
long long n;
long long xx[N];
long long vv[N];
long long sumvv[N];
void build(long long v, long long tl, long long tr) {
  pushing[v] = 0;
  if (tl == tr) {
    if (tl < n)
      t[v] = 0;
    else
      t[v] = sumvv[tl - n] - xx[tl - n];
    return;
  }
  long long tm = (tl + tr) >> 1;
  build(v << 1, tl, tm);
  build(v << 1 | 1, tm + 1, tr);
  t[v] = max(t[v << 1], t[v << 1 | 1]);
}
void push(long long v) {
  if (!pushing[v]) return;
  pushing[v << 1] += pushing[v];
  t[v << 1] += pushing[v];
  pushing[v << 1 | 1] += pushing[v];
  t[v << 1 | 1] += pushing[v];
  pushing[v] = 0;
}
long long get(long long v, long long tl, long long tr, long long l,
              long long r) {
  if (l > r) return -oo;
  if (tl == l && tr == r) return t[v];
  push(v);
  long long tm = (tl + tr) >> 1;
  return max(get(v << 1, tl, tm, l, min(tm, r)),
             get(v << 1 | 1, tm + 1, tr, max(tm + 1, l), r));
}
void upd(long long v, long long tl, long long tr, long long l, long long r,
         long long add) {
  if (l > r) return;
  if (tl == l && tr == r) {
    t[v] += add;
    pushing[v] += add;
    return;
  }
  push(v);
  long long tm = (tl + tr) >> 1;
  upd(v << 1, tl, tm, l, min(tm, r), add);
  upd(v << 1 | 1, tm + 1, tr, max(tm + 1, l), r, add);
  t[v] = max(t[v << 1], t[v << 1 | 1]);
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long c;
  cin >> n >> c;
  for (long long i = 0; i < long long(n); ++i) cin >> xx[i] >> vv[i];
  sumvv[0] = vv[0];
  for (long long i = 1; i < n; ++i) sumvv[i] = vv[i] + sumvv[i - 1];
  build(1, 0, n << 1);
  long long ans = get(1, 0, n << 1, n, n + n - 1);
  for (long long i = n - 1; i >= 0; --i) {
    long long add = c - xx[i];
    if (i != n - 1) add = xx[i + 1] - xx[i];
    add <<= 1;
    upd(1, 0, n << 1, i + 1, i + 1 + n, -add);
    upd(1, 0, n << 1, i, i + n, vv[i]);
    ans = max(ans, (get(1, 0, n << 1, i, i + n - 1)));
  }
  reverse(xx, xx + n);
  reverse(vv, vv + n);
  for (long long i = 0; i < n; ++i) {
    xx[i] = c - xx[i];
  }
  sumvv[0] = vv[0];
  for (long long i = 1; i < n; ++i) {
    sumvv[i] = vv[i] + sumvv[i - 1];
  }
  build(1, 0, n << 1);
  ans = max(ans, (get(1, 0, n << 1, n, n + n - 1)));
  for (long long i = n - 1; i >= 0; --i) {
    long long add = c - xx[i];
    if (i != n - 1) add = xx[i + 1] - xx[i];
    add <<= 1;
    upd(1, 0, n << 1, i + 1, i + 1 + n, -add);
    upd(1, 0, n << 1, i, i + n, vv[i]);
    ans = max(ans, (get(1, 0, n << 1, i, i + n - 1)));
  }
  cout << ans << endl;
}
