#include <bits/stdc++.h>
using namespace std;
long long ans = 0;
long long gobackr[108000];
long long gobackl[108000];
long long gor[108000];
long long gol[108000];
long long x[108000];
long long v[108000];
long long n, c;
int main() {
  cin >> n >> c;
  ans -= c;
  for (long long i = 0; i < n; i++) {
    cin >> x[i] >> v[i];
    ans += v[i];
  }
  ans = max(ans, 0LL);
  long long sum = 0;
  for (long long i = 0; i < n; i++) {
    sum += v[i];
    gobackr[i + 1] = max(gobackr[i], sum - 2 * x[i]);
    gor[i + 1] = max(gor[i], sum - x[i]);
  }
  sum = 0;
  for (long long i = n - 1; i >= 0; i--) {
    sum += v[i];
    gobackl[i] = max(gobackl[i + 1], sum - 2 * (c - x[i]));
    gol[i] = max(gol[i + 1], sum - (c - x[i]));
  }
  for (long long i = 0; i < n; i++) {
    ans = max(ans, gobackr[i] + gol[i]);
    ans = max(ans, gobackl[i] + gor[i]);
  }
  cout << ans << endl;
  return 0;
}
