#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  long long n, c;
  cin >> n >> c;
  vector<pair<long long, long long> > forward(n);
  for (auto &x : forward) {
    cin >> x.first >> x.second;
  }
  vector<pair<long long, long long> > backward(forward);
  for (auto &x : backward) {
    x.first = c - x.first;
  }
  long long ans = 1e15;
  vector<long long> energyForward(n, 0);
  for (long long i = 0; i < n; i++) {
    energyForward[i] = 0;
    if (i > 0) {
      energyForward[i] += energyForward[i - 1];
    }
    energyForward[i] += forward[i].second;
  }
  vector<long long> energyBackward(n, 0);
  for (long long i = n - 1; i >= 0; i--) {
    energyBackward[i] = 0;
    if (i < n - 1) {
      energyBackward[i] += energyBackward[i + 1];
    }
    energyBackward[i] += backward[i].second;
  }
  for (long long i = 0; i < n; i++) {
    energyForward[i] -= forward[i].first;
  }
  for (long long i = 0; i < n; i++) {
    energyBackward[i] -= backward[i].first;
  }
  long long mv = -1e15;
  vector<long long> maxLeft(n);
  vector<long long> maxRight(n);
  maxLeft[0] = energyForward[0];
  for (long long i = 1; i < n; i++) {
    maxLeft[i] = max(maxLeft[i - 1], energyForward[i]);
  }
  maxRight[n - 1] = energyBackward[n - 1];
  for (long long i = n - 2; i >= 0; i--) {
    maxRight[i] = max(maxRight[i + 1], energyBackward[i]);
  }
  for (long long i = 0; i < n; i++) {
    long long curr = energyForward[i];
    mv = max(curr, mv);
    if (i < n - 1) {
      long long back = maxRight[i + 1];
      back -= forward[i].first;
      back += curr;
      mv = max(mv, back);
    }
  }
  for (long long i = n - 1; i >= 0; i--) {
    long long curr = energyBackward[i];
    mv = max(curr, mv);
    if (i > 0) {
      long long front = maxLeft[i - 1];
      front -= backward[i].first;
      mv = max(mv, front);
    }
  }
  mv = max(mv, 0ll);
  cout << mv;
  return 0;
}
