#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = numeric_limits<ll>::max();
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  ll C;
  cin >> N;
  ;
  cin >> C;
  ;
  ll x[N], v[N];
  for (int i = 0; i < (N); ++i) {
    cin >> x[i];
    ;
    cin >> v[i];
    ;
  }
  ll sum_l[N + 1], sum_r[N + 1];
  sum_l[0] = sum_r[N] = 0;
  for (int i = 0; i < (N); ++i) sum_l[i + 1] = sum_l[i] + v[i];
  for (int i = (N - 1); i >= 0; --i) sum_r[i] = sum_r[i + 1] + v[i];
  for (int i = 0; i < (N); ++i) {
    sum_l[i + 1] -= x[i];
    sum_r[i] -= C - x[i];
  }
  ll max_l[N + 1], max_l2[N + 1];
  max_l[0] = -INF;
  max_l2[0] = -INF;
  for (int i = 0; i < (N); ++i) {
    max_l[i + 1] = max(max_l[i], sum_l[i + 1]);
    max_l2[i + 1] = max(max_l2[i], sum_l[i + 1] - x[i]);
  }
  ll ans = 0;
  for (int r = (N); r >= 0; --r) {
    if (r == N)
      chmax(ans, max_l[r]);
    else if (r == 0)
      chmax(ans, sum_r[r]);
    else {
      chmax(ans, sum_r[r] + max_l[r] - (C - x[r]));
      chmax(ans, sum_r[r] + max_l2[r]);
    }
  }
  cout << ans << "\n";
  return 0;
}
