#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100100, M = 1000000009;
long long n, x[MAXN], v[MAXN], c, ans = 0, tc;
long long xx[MAXN], mx[MAXN], ma = 0, in[MAXN];
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> c;
  for (int i = 0; i < n; i++) {
    cin >> x[i] >> v[i];
    xx[i] = c - x[i];
  }
  mx[n] = 0;
  in[n] = 0;
  for (int i = n - 1; i >= 0; i--) {
    mx[i] = mx[i + 1];
    in[i] = in[i + 1];
    tc += v[i];
    if (mx[i] < tc - xx[i]) {
      mx[i] = tc - xx[i];
      in[i] = xx[i];
    }
  }
  ans = max(ans, mx[0]);
  tc = 0;
  for (int i = 0; i < n; i++) {
    tc += v[i];
    if (tc - x[i] > ans) {
      ans = tc - x[i];
    }
    if (tc - 2 * x[i] + mx[i + 1] > ans) {
      ans = tc - 2 * x[i] + mx[i + 1];
    }
    if (tc - x[i] + mx[i + 1] - in[i + 1] > ans) {
      ans = tc - x[i] + mx[i + 1] - in[i + 1];
    }
  }
  cout << ans;
  return 0;
}
