#include <bits/stdc++.h>
using namespace std;
const int MAXN = 10000 + 5;
const int INF = 0x3f3f3f3f;
long long x[MAXN], v[MAXN];
long long dp1[MAXN], dp2[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]);
  long long sm = 0;
  for (int i = 1; i <= n; i++) {
    sm += v[i] - (x[i] - x[i - 1]);
    dp1[i] = max(sm, dp1[i - 1]);
  }
  x[n + 1] = c;
  sm = 0;
  for (int i = n; i >= 1; i--) {
    sm += v[i] - (x[i + 1] - x[i]);
    dp2[i] = max(sm, dp2[i + 1]);
  }
  long long ans = max(dp1[n], dp2[1]);
  sm = 0;
  for (int i = n; i >= 1; i--) {
    sm += v[i] - (x[i + 1] - x[i]);
    ans = max(ans, sm - (c - x[i]) + dp1[i - 1]);
  }
  sm = 0;
  for (int i = 1; i <= n; i++) {
    sm += v[i] - (x[i] - x[i - 1]);
    ans = max(ans, sm - x[i] + dp2[i + 1]);
  }
  printf("%I64d\n", ans);
  return 0;
}
