#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ll N, C;
  cin >> N >> C;
  ll x[N], v[N], rx[N];
  for (int i = 0; i < N; i++) {
    cin >> x[i] >> v[i];
    rx[i] = C - x[i];
  }
  ll cost = 0, ans = 0;
  for (int i = 0; i < N; i++) {
    cost += v[i];
    ll rcost = 0;
    for (int j = N - 1; j > i; j--) {
      rcost += v[j];
      ans = max(ans, cost - 2 * x[i] + rcost - rx[j]);
    }
    ans = max(ans, cost - x[i]);
  }
  cost = 0;
  for (int i = N - 1; i >= 0; i--) {
    cost += v[i];
    ll rcost = 0;
    for (int j = 0; j < i; j++) {
      rcost += v[j];
      ans = max(ans, cost - 2 * rx[i] + rcost - x[j]);
    }
    ans = max(ans, cost - rx[i]);
  }
  cout << ans << endl;
  return 0;
}
