#include <bits/stdc++.h>
using namespace std;
namespace {
struct input_returnner {
  long long N;
  input_returnner(long long N_ = 0) : N(N_) {}
  template <typename T>
  operator vector<T>() const {
    vector<T> res(N);
    for (auto &a : res) cin >> a;
    return std::move(res);
  }
  template <typename T>
  operator T() const {
    T res;
    cin >> res;
    return res;
  }
  template <typename T>
  T operator-(T right) {
    return T(input_returnner()) - right;
  }
  template <typename T>
  T operator+(T right) {
    return T(input_returnner()) + right;
  }
  template <typename T>
  T operator*(T right) {
    return T(input_returnner()) * right;
  }
  template <typename T>
  T operator/(T right) {
    return T(input_returnner()) / right;
  }
  template <typename T>
  T operator<<(T right) {
    return T(input_returnner()) << right;
  }
  template <typename T>
  T operator>>(T right) {
    return T(input_returnner()) >> right;
  }
};
template <typename T>
input_returnner in() {
  return in<T>();
}
input_returnner in() { return input_returnner(); }
input_returnner in(long long N) { return std::move(input_returnner(N)); }
}  // namespace
const long long MOD = 1e9 + 7;
void solve();
signed main() {
  cin.tie(0), ios::sync_with_stdio(false), cout << setprecision(15);
  solve();
  return 0;
}
template <class T>
class segtree {
 private:
  long long n;
  vector<T> dat;
  T query(long long a, long long b, long long k, long long l, long long r) {
    if (r <= a || b <= l) return numeric_limits<T>::max();
    if (a <= l & r <= b)
      return dat[k];
    else {
      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 min(vl, vr);
    }
  }

 public:
  segtree(long long n_) {
    n = 1;
    while (n < n_) n *= 2;
    dat.resize(2 * n - 1);
    for (long long i = 0; i < 2 * n - 1; ++i) dat[i] = numeric_limits<T>::max();
  }
  void update(long long k, long long a) {
    k += n - 1;
    dat[k] = a;
    while (k > 0) {
      k = (k - 1) / 2;
      dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
    }
  }
  long long query(long long a, long long b) { return query(a, b, 0, 0, n); }
};
void solve() {
  long long N, C;
  cin >> N >> C;
  vector<pair<long long, long long> > X;
  vector<pair<long long, long long> > IX;
  for (long long i = 0; i < (N); i++) {
    long long x, v;
    cin >> x >> v;
    X.emplace_back(x, v);
    IX.emplace_back(C - x, v);
  }
  sort((X).begin(), (X).end());
  sort((IX).begin(), (IX).end());
  vector<long long> sumIX(N);
  vector<long long> sumX(N);
  long long dis = 0;
  sumIX[0] = IX[0].second - IX[0].first;
  vector<long long> imaxs(N);
  vector<long long> maxs(N);
  pair<long long, long long> ma;
  long long res = 0;
  sumIX[0] = IX[0].second - IX[0].first;
  imaxs[0] = sumIX[0];
  for (long long i = (1); i < (N); i++) {
    sumIX[i] = sumIX[i - 1] + IX[i].second - (IX[i].first - IX[i - 1].first);
    imaxs[i] = max(sumIX[i], imaxs[i - 1]);
    res = max(res, sumIX[i]);
  }
  reverse((sumIX).begin(), (sumIX).end());
  reverse((imaxs).begin(), (imaxs).end());
  reverse((IX).begin(), (IX).end());
  sumX[0] = X[0].second - X[0].first;
  maxs[0] = sumX[0];
  for (long long i = (1); i < (N); i++) {
    sumX[i] = sumX[i - 1] + X[i].second - (X[i].first - X[i - 1].first);
    maxs[i] = max(sumX[i], maxs[i - 1]);
    res = max(res, sumX[i]);
  }
  for (long long i = 0; i < (N - 1); i++) {
    long long val = sumX[i] - X[i].first + imaxs[i + 1];
    if (res < val) res = val;
  }
  for (long long i = (1); i < (N); i++) {
    long long val = sumIX[i] - IX[i].first + maxs[i - 1];
    if (res < val) res = val;
  }
  cout << res << endl;
}
