#include <bits/stdc++.h>
using namespace std;
long long int x[100005];
long long int v[100005];
long long int sums[100005];
long long int maxes[100005];
long long int xes[100005];
long long int n, c;
int main() {
  cin >> n >> c;
  for (int i = 0; i < n; i++) {
    cin >> x[i] >> v[i];
  }
  long long int ans = 0;
  long long int cals = 0;
  for (int i = 0; i < n; i++) {
    cals += v[i];
    ans = max(ans, cals - x[i]);
  }
  cals = 0;
  for (int i = n - 1; i >= 0; i--) {
    cals += v[i];
    ans = max(ans, cals - (c - x[i]));
  }
  sums[0] = v[0];
  maxes[0] = sums[0] - x[0];
  xes[0] = x[0];
  for (int i = 1; i < n; i++) {
    sums[i] = sums[i - 1] + v[i];
    maxes[i] = max(maxes[i - 1], sums[i] - x[i]);
    xes[i] = maxes[i] > maxes[i - 1] ? x[i] : x[i - 1];
  }
  for (int i = 1; i < n; i++) {
    long long int left_sum = sums[n - 1] - sums[i - 1] - (c - x[i]);
    long long int dbld = (c - x[i] > xes[i - 1]) ? xes[i - 1] : c - x[i];
    ans = max(ans, maxes[i - 1] + left_sum - dbld);
  }
  cout << ans;
}
