#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T>
inline T GET() {
  T x;
  cin >> x;
  return x;
}
void init();
void solve();
signed main() {
  init();
  solve();
}
ll N, C;
vector<ll> x, v, xr, vr;
ll r1, r2, l1, l2;
void init() {
  cin >> N >> C;
  for (ll i = 0; (i) < (ll)(N); (i)++) {
    x.push_back((GET<ll>()));
    v.push_back((GET<ll>()));
  }
  for (ll i = (ll)N - 1; (i) >= 0; (i)--) {
    xr.push_back((C - x[i]));
    vr.push_back((v[i]));
  }
}
void calc(vector<ll>& X, vector<ll>& V, vector<vector<ll>>& score) {
  ll sum = 0;
  score[0][0] = score[1][0] = 0;
  for (ll i = 0; (i) < (ll)(N); (i)++) {
    sum += V[i];
    score[0][i + 1] = max(score[0][i], sum - X[i]);
    score[1][i + 1] = max(score[1][i], sum - 2 * X[i]);
  }
}
void solve() {
  vector<vector<vector<ll>>> score;
  score.resize(2, vector<vector<ll>>(2, vector<ll>(N + 1, 0)));
  calc(x, v, score[0]);
  calc(xr, vr, score[1]);
  ll res = max(score[1][0][N], score[0][0][N]);
  for (ll i = 0; (i) < (ll)(2); (i)++) {
    for (ll j = 0; (j) < (ll)(2); (j)++) {
      for (ll k = 0; (k) < (ll)(N + 1); (k)++) {
        cerr << score[i][j][k] << " ";
      }
      cerr << endl;
    }
    cerr << endl;
  }
  for (ll i = (ll)(1); (i) < (ll)(N); (i)++) {
    res = max(res, score[0][0][i] + score[1][1][N - i - 1]);
    res = max(res, score[0][1][i] + score[1][0][N - i - 1]);
  }
  cout << res << endl;
}
