#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100000;
long long x[MAXN + 5], v[MAXN + 5];
long long dp1[MAXN + 5], dp2[MAXN + 5];
int main() {
  int N;
  long long C;
  scanf("%d%lld", &N, &C);
  for (int i = 1; i <= N; i++) {
    scanf("%lld%lld", &x[i], &v[i]);
    dp1[i] = dp1[i - 1] - (x[i] - x[i - 1]) + v[i];
  }
  for (int i = N; i >= 1; i--) {
    x[i] = C - x[i];
    dp2[i] = dp2[i + 1] - (x[i] - x[i + 1]) + v[i];
  }
  long long Max1 = 0, Max2 = 0, ans = 0;
  for (int i = N; i >= 1; i--) {
    ans = max(ans, max(dp1[i] + Max1, dp1[i] + Max2 - (C - x[i])));
    Max1 = max(Max1, dp2[i] - x[i]);
    Max2 = max(Max2, dp2[i]);
  }
  printf("%lld", ans);
}
