#include <bits/stdc++.h>
using namespace std;
int n;
long long c;
long long xVal[100002];
long long v[100002];
int f[100002];
long long calc(int a, int b) {
  if (a < b) return -1e18;
  long long ret = 0;
  long long x = c - xVal[a];
  long long y = xVal[b];
  ret += v[n] - v[a - 1];
  ret += v[b];
  ret -= min({2 * x + y, 2 * y + x, xVal[n], c - xVal[1]});
  if (a == b) {
    return v[n] - min({2 * x + y, 2 * y + x, xVal[n], c - xVal[1]});
  }
  return ret;
}
long long solve() {
  long long ret = 0;
  for (int a = 0; a <= n + 1; a++) {
    ret = max(ret, calc(a, f[a]));
  }
  return ret;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> c;
  for (int i = 1; i <= n; i++) cin >> xVal[i] >> v[i];
  for (int i = 1; i <= n; i++) v[i] += v[i - 1];
  xVal[n + 1] = c;
  xVal[0] = 0;
  long long mx = 0;
  int w = 0;
  for (int i = 0; i <= n + 1; i++) {
    long long cur = v[i] - xVal[i];
    f[i] = w;
    if (cur > mx) {
      mx = cur;
      w = i;
    }
  }
  cout << solve() << '\n';
  return 0;
}
