#include <bits/stdc++.h>
using namespace std;
using int64 = int_fast64_t;
using PAIR = pair<int, int>;
constexpr int INF = 1 << 30;
constexpr int64 LINF = 1LL << 60;
constexpr int MOD = 1e9 + 7;
constexpr int MAX_N = 1e5 + 1;
template <typename T>
void MACRO_VAR_Scan(T &t) {
  cin >> t;
}
template <typename First, typename... Rest>
void MACRO_VAR_Scan(First &first, Rest &...rest) {
  cin >> first;
  MACRO_VAR_Scan(rest...);
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ;
  int64 n, c;
  MACRO_VAR_Scan(n, c);
  ;
  vector<int64> x(n), v(n);
  for (int64 i = 0; i < (n); ++i) {
    cin >> x[i] >> v[i];
  }
  auto solve = [=]() {
    vector<int64> sm(n + 1, 0), rev(n, 0), rev_sm(n + 1, 0), rev_ans(n + 1, 0);
    int64 res = 0;
    sm[0] = v[0];
    for (int64 i = 0; i < (n); ++i) {
      sm[i] = sm[i - 1] + v[i];
    }
    rev_sm[n - 1] = v[n - 1];
    for (int64 i = (n - 2) - 1; i >= 0; --i) {
      rev_sm[i] = rev_sm[i + 1] + v[i];
    }
    for (int64 i = 0; i < (n); ++i) {
      rev[i] = c - x[i];
    }
    rev_ans[n - 1] = rev_sm[n - 1] - rev[n - 1];
    for (int64 i = (n - 2) - 1; i >= 0; --i) {
      rev_ans[i] = rev_sm[i] - rev[i];
      rev_ans[i] = max(rev_ans[i], rev_ans[i + 1]);
    }
    for (int64 i = 0; i < (n); ++i) {
      int64 tmp_sm = sm[i] - x[i];
      res = max(res, tmp_sm);
      tmp_sm -= x[i];
      if (i < n - 1) tmp_sm += rev_sm[i + 1];
      res = max(res, tmp_sm);
    }
    return res;
  };
  int64 ans = solve();
  reverse((v).begin(), (v).end());
  for (int64 i = 0; i < (n); ++i) x[i] = c - x[i];
  reverse((x).begin(), (x).end());
  ans = max(ans, solve());
  cout << (ans);
  cout << "\n";
  ;
  return 0;
}
