#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int n, v[N];
long long c, x[N], s[N], a[N], b[N], ans, MX, mx;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> c;
  for (int i = 1; i <= n; i++) {
    cin >> x[i] >> v[i];
    s[i] = s[i - 1] + v[i];
    a[i] = max(a[i - 1], s[i] - 2 * x[i]);
    b[i] = max(b[i - 1], s[i] - x[i]);
  }
  for (int i = n; i; i--) {
    ans = max(ans, max(a[i - 1] + mx, b[i - 1] + MX));
    MX = max(MX, s[n] - s[i - 1] - 2 * (c - x[i]));
    mx = max(mx, s[n] - s[i - 1] - (c - x[i]));
  }
  cout << ans << "\n";
}
