#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 500;
long long dp[2][maxn];
long long g[2][maxn];
long long x[maxn], v[maxn];
long long n, c, sum;
int main() {
  scanf("%I64d %I64d", &n, &c);
  for (int i = 1; i <= n; i++) {
    scanf("%I64d %I64d", &x[i], &v[i]);
  }
  for (int i = 1; i <= n; i++) {
    sum += v[i];
    dp[0][i] = max(dp[0][i - 1], sum - x[i]);
    g[0][i] = sum - 2 * x[i];
  }
  sum = 0;
  for (int i = n; i >= 1; i--) {
    sum += v[i];
    dp[1][i] = max(dp[1][i + 1], sum - (c - x[i]));
    g[1][i] = sum - 2 * (c - x[i]);
  }
  long long ans = max(dp[0][n], dp[1][1]);
  for (int i = 1; i <= n; i++) {
    ans = max(ans, g[0][i] + dp[1][i + 1]);
    ans = max(ans, g[1][i] + dp[0][i - 1]);
  }
  printf("%I64d\n", ans);
  return 0;
}
