#include <bits/stdc++.h>
using namespace std;
const int MaxN = 1e5 + 7;
long long a[MaxN], b[MaxN];
long long x[MaxN], v[MaxN];
int main() {
  long long n, c;
  scanf("%I64d%I64d", &n, &c);
  for (int i = 1; i <= n; i++) scanf("%I64d%I64d", &x[i], &v[i]);
  for (long long i = 1; i <= n; i++) a[i] = a[i - 1] + v[i] - (x[i] - x[i - 1]);
  x[n + 1] = c;
  for (long long i = n; i >= 1; i--) b[i] = b[i + 1] + v[i] - (x[i + 1] - x[i]);
  for (long long i = 2; i <= n; i++) a[i] = max(a[i - 1], a[i]);
  for (long long i = n - 1; i >= 1; i--) b[i] = max(b[i], b[i + 1]);
  long long ans = max(0LL, max(a[n], b[1]));
  for (long long i = 1; i <= n - 2; i++) ans = max(ans, a[i] - x[i] + b[i + 1]);
  for (long long i = 2; i <= n; i++)
    ans = max(ans, b[i] - (c - x[i]) + a[i - 1]);
  printf("%I64d\n", ans);
}
