#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
int main() {
  int N;
  cin >> N;
  ll C;
  cin >> C;
  vector<Pl> xv(N);
  for (int i = (int)(0); i < (int)(N); i++) {
    cin >> xv[i].first >> xv[i].second;
  }
  vector<ll> sumv(N + 1);
  for (int i = (int)(0); i < (int)(N); i++) {
    sumv[i + 1] = sumv[i] + xv[i].second;
  }
  vector<ll> left(N);
  left[0] = xv[0].second - xv[0].first;
  for (int i = (int)(0); i < (int)(N - 1); i++) {
    left[i + 1] = left[i] + xv[i + 1].second - (xv[i + 1].first - xv[i].first);
  }
  vector<ll> leftmax(N);
  vector<ll> xmax(N);
  ll now = -(long long)4e18;
  ll nowx = 0;
  for (int i = (int)(0); i < (int)(N); i++) {
    if (now < left[i]) {
      now = left[i];
      nowx = xv[i].first;
    }
    leftmax[i] = now;
    xmax[i] = nowx;
  }
  ll ans = 0;
  for (int i = (int)(1); i < (int)(N); i++) {
    now = 0;
    now += leftmax[i - 1];
    now += sumv[N] - sumv[i] - (C - (xv[i].first - xmax[i - 1]));
    ans = max(ans, now);
  }
  for (int i = (int)(1); i < (int)(N); i++) {
    now = 0;
    now += leftmax[i - 1];
    now += sumv[N] - sumv[i] - (C - xv[i].first) * 2;
    ans = max(ans, now);
  }
  for (int i = (int)(0); i < (int)(N); i++) {
    now = leftmax[i];
    ans = max(ans, now);
  }
  for (int i = (int)(0); i < (int)(N); i++) {
    now = sumv[N] - sumv[i];
    now -= C - xv[i].first;
    ans = max(ans, now);
  }
  cout << ans << endl;
}
