#include <bits/stdc++.h>
using namespace std;
const int MAX = 100000;
int main() {
  int N, v;
  int64_t C, x;
  static pair<int64_t, int> sushi[MAX + 1];
  cin >> N >> C;
  sushi[0] = make_pair(0, 0);
  for (int i = 1; i <= N; i++) {
    cin >> x >> v;
    sushi[i] = make_pair(x, v);
  }
  static int64_t calL[MAX + 1], calR[MAX + 1];
  static int maxR[MAX + 1];
  calL[0] = 0;
  calR[0] = 0;
  for (int i = 1; i <= N; i++) {
    calL[i] =
        calL[i - 1] + sushi[i].second - (sushi[i].first - sushi[i - 1].first);
    calR[i] = calR[i - 1] + sushi[N - i + 1].second -
              (i == 1 ? C - sushi[N].first
                      : sushi[N - i + 2].first - sushi[N - i + 1].first);
  }
  maxR[N] = 0;
  for (int i = 1; i <= N; i++) {
    if (calR[maxR[N - i + 1]] < calR[i])
      maxR[N - i] = i;
    else
      maxR[N - i] = maxR[N - i + 1];
  }
  int64_t ans = calR[maxR[N]];
  for (int i = 1; i <= N; i++) {
    ans = max(ans, max(calL[i], calL[i] + calR[maxR[i]] -
                                    min(C - sushi[N - maxR[i] + 1].first,
                                        sushi[i].first)));
  }
  cout << ans;
  return 0;
}
