#include <bits/stdc++.h>
using namespace std;
auto chmax = [](int &a, int b) { a = max(a, b); };
auto chmin = [](int &a, int b) { a = min(a, b); };
const int INF = 100000000;
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1};
const int dy[4] = {1, 0, -1, 0};
bool isDebugMode = 1;
int n;
long long c;
long long x[100100];
long long v[100100];
long long k[2][100100];
void solve() {
  k[0][0] = v[0] - x[0];
  for (int i = 0 + 1; i <= n - 1; i++) {
    k[0][i] = k[0][i - 1] + v[i] - (x[i] - x[i - 1]);
  }
  k[1][0] = v[n - 1] - (c - x[n - 1]);
  for (int i = 0 + 1; i <= n - 1; i++) {
    k[1][i] = k[1][i - 1] + v[n - 1 - i] - (x[n - i] - x[n - i - 1]);
  }
  long long mc = c / 2;
  long long ans = 0;
  long long k1 = 0, k2 = 0;
  for (int i = 0; i < n; i++) {
    if (x[i] >= mc)
      break;
    else {
      k1 = max(k1, k[0][i]);
    }
  }
  for (int i = 0; i < n; i++) {
    if (x[n - i - 1] < mc)
      break;
    else {
      k2 = max(k2, k[1][i]);
    }
  }
  for (int i = 0; i < n; i++) {
    ans = max(ans, k[0][i]);
    if (x[i] < mc) ans = max(ans, k[0][i] - x[i] + k2);
  }
  for (int i = 0; i < n; i++) {
    ans = max(ans, k[1][i]);
    if (x[n - i - 1] >= mc) ans = max(ans, k[1][i] - (c - x[n - 1 - i]) + k1);
  }
  cout << ans << endl;
}
int main() {
  cin >> n >> c;
  for (int i = 0; i < n; i++) {
    cin >> x[i] >> v[i];
  }
  solve();
  return 0;
}
