#include <bits/stdc++.h>
using namespace std;
template <typename T, typename E>
class SegmentTree {
 public:
  typedef function<T(T, T)> Operator;
  typedef function<T(T, E)> Apply;
  vector<T> data;
  long long n;
  T e;
  Operator op;
  Apply apply;
  SegmentTree(long long _n, T e, Operator op, Apply apply)
      : e(e), op(op), apply(apply) {
    for (n = 1; n < _n; n *= 2)
      ;
    data.resize(n * 2 - 1, e);
  }
  SegmentTree(const vector<T> &vec, T e, Operator op, Apply apply)
      : e(e), op(op), apply(apply) {
    for (n = 1; n < vec.size(); n *= 2)
      ;
    data.resize(n * 2 - 1, e);
    for (long long i = ((long long)0); i < ((long long)vec.size()); i++)
      data[i + n - 1] = vec[i];
    for (long long i = n - 2; i >= 0; i--)
      data[i] = op(data[i * 2 + 1], data[i * 2 + 2]);
  }
  T query(long long a, long long b) { return query(a, b, 0, 0, n); }
  T query(long long a, long long b, long long k, long long l, long long r) {
    if (r <= a || b <= l) return e;
    if (a <= l && r <= b) return data[k];
    T vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
    T vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
    return op(vl, vr);
  }
  void update(long long k, E x) {
    k += n - 1;
    data[k] = apply(data[k], x);
    while (k > 0) {
      k = (k - 1) / 2;
      data[k] = op(data[k * 2 + 1], data[k * 2 + 2]);
    }
  }
};
int main(void) {
  long long N, C;
  cin >> N >> C;
  vector<long long> X(N), V(N);
  for (long long i = ((long long)0); i < ((long long)N); i++)
    cin >> X[i] >> V[i];
  vector<long long> sum1(N + 1, 0), sum2(N + 1, 0);
  for (long long i = ((long long)0); i < ((long long)N); i++)
    sum1[i + 1] = sum1[i] + V[i];
  for (long long i = ((long long)0); i < ((long long)N); i++)
    sum2[i + 1] = sum2[i] + V[N - i - 1];
  SegmentTree<long long, long long>::Operator op =
      [](long long a, long long b) { return max(a, b); };
  SegmentTree<long long, long long>::Apply apply =
      [](long long a, long long x) { return x; };
  SegmentTree<long long, long long> segtree1(N, -(1LL << 60), op, apply),
      segtree2(N, 0, op, apply);
  for (long long i = ((long long)0); i < ((long long)N); i++)
    segtree1.update(i, sum1[i + 1] - X[i]);
  for (long long i = ((long long)0); i < ((long long)N); i++)
    segtree2.update(i, sum2[i + 1] - (C - X[N - i - 1]));
  long long ans = 0;
  for (long long i = ((long long)0); i < ((long long)N); i++) {
    long long t = sum1[i + 1] - X[i];
    ans = max(ans, t);
    ans = max(ans, t + segtree2.query(0, N - i - 2) - X[i]);
  }
  for (long long i = ((long long)0); i < ((long long)N); i++) {
    long long t = sum2[i + 1] - (C - X[N - i - 1]);
    ans = max(ans, t);
    ans = max(ans, t + segtree1.query(0, N - i - 2) - (C - X[N - i - 1]));
  }
  cout << ans << endl;
}
