#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
long long dp[maxn] = {0}, dp1[maxn] = {0}, x[maxn], v[maxn];
long long max(long long x, long long y) { return x > y ? x : y; }
long long min(long long x, long long y) { return x < y ? x : y; }
int main() {
  int n;
  long long c;
  cin >> n >> c;
  for (int i = 0; i < n; i++) {
    cin >> x[i] >> v[i];
    if (i == 0)
      dp[i] = v[i] - x[i];
    else
      dp[i] = dp[i - 1] + v[i] - (x[i] - x[i - 1]);
  }
  for (int i = n - 1; i >= 0; i--) {
    if (i == n - 1)
      dp1[i] = max(dp1[i], v[i] - c + x[i]);
    else
      dp1[i] = max(dp1[i], dp1[i + 1] - x[i + 1] + x[i] + v[i]);
  }
  long long maxx = 0;
  for (int i = 0; i < n; i++) maxx = max(dp[i], maxx);
  for (int i = 0; i < n; i++)
    for (int j = i + 1; j < n; j++)
      maxx = max(maxx, dp1[j] + dp[i] - min(x[i], c - x[j]));
  cout << maxx << endl;
}
