#include <bits/stdc++.h>
const int inf = 103974182;
using namespace std;
int n;
long long c;
long long a[100005];
long long v[100005];
long long m[100005];
set<long long> squ;
long long maxn;
void func() {
  memset(m, 0, sizeof(m));
  long long now = 0;
  for (int i = 0; i < n; i++) {
    now += v[i];
    m[i] = max(now - a[i], (i - 1 < 0 ? 0 : m[i - 1]));
  }
  maxn = max(maxn, m[n - 1]);
  long long d = 0;
  now = 0;
  for (int i = n - 1; i >= 0; i--) {
    d = c - a[i];
    now += v[i];
    maxn = max(maxn, now - d - d + (i - 1 < 0 ? 0 : m[i - 1]));
    maxn = max(maxn, now - d);
  }
}
int main() {
  cin >> n >> c;
  for (int i = 0; i < n; i++) {
    scanf("%I64d%I64d", a + i, v + i);
  }
  long long now = 0;
  for (int i = n - 1; i >= 0; i--) {
    now += v[i];
    m[i] = max(now - (c - a[i]), m[i + 1]);
  }
  maxn = m[0];
  long long d = 0;
  now = 0;
  for (int i = 0; i < n; i++) {
    d = a[i];
    now += v[i];
    maxn = max(maxn, now - d - d + m[i + 1]);
    maxn = max(maxn, now - d);
  }
  func();
  cout << maxn << endl;
  return 0;
}
