#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using G = vector<vector<int>>;
int di[] = {0, -1, 0, 1};
int dj[] = {1, 0, -1, 0};
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  LL c;
  cin >> c;
  vector<LL> x(n), v(n), f(n + 1, 0), g(n + 1, 0);
  for (int i = (0); i < (n); i++) cin >> x[i] >> v[i];
  LL now = 0;
  for (int i = (0); i < (n); i++) {
    now += v[i];
    f[i + 1] = max(f[i], now - x[i]);
  }
  now = 0;
  for (int i = (n)-1; i >= (0); i--) {
    now += v[i];
    g[i] = max(g[i + 1], now - (c - x[i]));
  }
  LL ans = max({0LL, f[n], g[1]});
  now = 0;
  for (int i = (n)-1; i >= (1); i--) {
    now += v[i];
    ans = max(ans, now - 2LL * (c - x[i]) + f[i]);
  }
  now = 0;
  for (int i = (0); i < (n - 1); i++) {
    now += v[i];
    ans = max(ans, now - 2LL * x[i] + g[i + 2]);
  }
  cout << ans << endl;
  return 0;
}
