#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, v[100010], rv[100010];
  long long sumv[100010], sumrv[100010];
  long long c, x[100010], rx[100010];
  long long maxS[100010], maxrS[100010];
  scanf("%d%lld", &n, &c);
  for (int i = 0; i < n; i++) {
    scanf("%lld%d", x + i, v + i);
    rv[n - 1 - i] = v[i];
    rx[n - 1 - i] = c - x[i];
  }
  long long ans = 0;
  sumv[0] = v[0];
  sumrv[0] = rv[0];
  maxS[0] = v[0] - x[0] * 2;
  maxrS[0] = rv[0] - rx[0] * 2;
  ans = max(ans, sumv[0] - x[0]);
  ans = max(ans, sumrv[0] - rx[0]);
  for (int i = 1; i < n; i++) {
    sumv[i] = sumv[i - 1] + v[i];
    sumrv[i] = sumrv[i - 1] + rv[i];
    maxS[i] = max(sumv[i] - x[i] * 2, maxS[i - 1]);
    maxrS[i] = max(sumrv[i] - rx[i] * 2, maxrS[i - 1]);
    ans = max(ans, sumv[i] - x[i]);
    ans = max(ans, sumrv[i] - rx[i]);
  }
  maxrS[0] = 0;
  maxS[0] = 0;
  for (int i = 0; i < n - 1; i++) {
    ans = max(ans, sumv[i] - x[i] + maxrS[n - i - 2]);
    ans = max(ans, sumrv[i] - rx[i] + maxS[n - i - 2]);
  }
  cout << ans << endl;
  return 0;
}
