#include <bits/stdc++.h>
using namespace std;
struct edge {
  int from, to;
  long long cost;
};
int main() {
  std::ios::sync_with_stdio(0);
  cin.tie(0);
  long long N, C;
  cin >> N >> C;
  vector<pair<long long, long long> > sushi(N + 2,
                                            pair<long long, long long>(0, 0));
  for (int i = 1; i < N + 1; i++) cin >> sushi[i].first >> sushi[i].second;
  sushi[N + 1].first = C;
  sushi[N + 1].second = 0;
  vector<long long> asc(N + 2, 0), asc_max(N + 2, LLONG_MIN), desc(N + 2, 0),
      desc_max(N + 2, LLONG_MIN);
  for (int i = 1; i < N + 1; i++) {
    asc[i] =
        asc[i - 1] + sushi[i].second - (sushi[i].first - sushi[i - 1].first);
    asc_max[i] = max(asc[i], asc_max[i - 1]);
  }
  asc[N + 1] = asc[N];
  for (int i = N; i >= 1; i--) {
    desc[i] =
        desc[i + 1] + sushi[i].second - (sushi[i + 1].first - sushi[i].first);
    desc_max[i] = max(desc[i], desc_max[i + 1]);
  }
  desc[0] = desc[1];
  long long ans = 0LL;
  for (int i = 0; i < N + 2; i++) {
    long long tmp = asc[i];
    long long d = desc_max[i + 1];
    if (d > sushi[i].first) tmp += -sushi[i].first + d;
    ans = max(ans, tmp);
    tmp = desc[i];
    d = asc_max[i - 1];
    if (d > C - sushi[i].first) tmp += -(C - sushi[i].first) + d;
    ans = max(ans, tmp);
  }
  cout << ans << endl;
}
