#include <bits/stdc++.h>
using namespace std;
template <typename X>
bool exist(vector<X> vec, X item) {
  return find(vec.begin(), vec.end(), item) != vec.end();
}
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
long long N;
long long C;
vector<long long> x, v;
vector<long long> useR;
map<long long, long long> sumle, sumri;
long long findR(long long till) {
  long long l = 0;
  long long r = useR.size();
  while ((l + 1) < r) {
    long long m = (l + r) / 2;
    if (useR[m] >= till) {
      r = m;
    } else {
      l = m;
    }
  }
  if (till == 0)
    return useR[useR.size() - 1];
  else
    return useR[l];
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long nowvalue, before;
  cin >> N >> C;
  x.push_back(0);
  v.push_back(0);
  for (long long i = (long long)0; i < (long long)N; i++) {
    long long xi, vi;
    cin >> xi >> vi;
    x.push_back(xi);
    v.push_back(vi);
  }
  N++;
  nowvalue = 0;
  before = 0;
  for (long long i = (long long)0; i < (long long)N; i++) {
    nowvalue += v[i];
    long long su = nowvalue - x[i];
    if (su >= before) {
      before = su;
      useR.push_back(i);
    }
  }
  nowvalue = 0;
  for (long long i = (long long)0; i < (long long)N; i++) {
    nowvalue += v[i];
    sumri[i] = nowvalue;
  }
  nowvalue = 0;
  for (long long i = N - 1; i > 0; i--) {
    nowvalue += v[i];
    sumle[i] = nowvalue;
  }
  sumle[0] = 0;
  long long ans = 0;
  for (long long i = (long long)0; i < (long long)N; i++) {
    long long l = i;
    long long r = findR(l);
    long long ldi = C - x[l];
    if (l == 0) ldi = 0;
    long long ans1 = sumle[l] + sumri[r] - ldi - x[r] - x[r];
    long long ans2 = sumle[l] + sumri[r] - ldi - x[r] - ldi;
    ans1 = max(ans1, ans2);
    ans = max(ans, ans1);
  }
  cout << ans << endl;
  return 0;
}
