#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
struct T {
  long long a, b;
} D[N];
long long A[N];
T stk[N];
int cnt = 0;
int main() {
  long long n, c;
  scanf("%lld%lld", &n, &c);
  for (int i = 1; i <= n; i++) scanf("%lld%lld", &D[i].a, &D[i].b);
  int j = n;
  long long ans = 0;
  D[n + 1].a = c;
  for (int i = n; i >= 1; i--) {
    A[i] = A[i + 1] + D[i].b - (D[i + 1].a - D[i].a);
    if (A[i] >= ans) ans = A[i], stk[cnt++] = {ans, i};
  }
  memset(A, 0, sizeof(A));
  for (int i = 1; i <= n; i++) {
    A[i] = A[i - 1] + D[i].b - (D[i].a - D[i - 1].a);
    while (cnt > 0 && stk[cnt - 1].b <= i) cnt--;
    if (cnt > 0) {
      long long op = A[i] - D[i].a + stk[cnt - 1].a;
      long long op1 = A[i] - (c - D[stk[cnt - 1].b].a) + stk[cnt - 1].a;
      ans = max(ans, op);
      ans = max(ans, op1);
    }
    ans = max(ans, A[i]);
  }
  cout << ans << '\n';
}
