#include <bits/stdc++.h>
using namespace std;
long long int const MOD = 1000000007;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long int n, c;
  cin >> n >> c;
  vector<long long int> x(n + 1, 0), v(n + 1, 0);
  for (int i = 1; i < n + 1; i++) {
    cin >> x[i] >> v[i];
  }
  vector<long long int> lefttotal(n + 1, 0), maxlefttotal(n + 1, 0);
  for (int i = 1; i < n + 1; i++) {
    lefttotal[i] = lefttotal[i - 1] + v[i];
  }
  for (int i = 1; i < n + 1; i++) {
    maxlefttotal[i] = max(maxlefttotal[i - 1], lefttotal[i] - x[i]);
  }
  vector<long long int> righttotal(n + 1, 0), maxrighttotal(n + 1, 0);
  for (int i = 1; i < n + 1; i++) {
    righttotal[i] = righttotal[i - 1] + v[n - i + 1];
  }
  for (int i = 1; i < n + 1; i++) {
    maxrighttotal[i] =
        max(maxrighttotal[i - 1], righttotal[i] - (c - x[n + 1 - i]));
  }
  long long int ans = 0;
  for (int i = 1; i < n + 1; i++) {
    ans = max(ans, lefttotal[i] - x[i]);
    ans = max(ans, lefttotal[i] - 2 * x[i] + maxrighttotal[n - i]);
    ans = max(ans, righttotal[i] - 2 * (c - x[n + 1 - i]));
    ans =
        max(ans, righttotal[i] - 2 * (c - x[n + 1 - i]) + maxlefttotal[n - i]);
  }
  cout << ans << endl;
  return 0;
}
