#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
long long n, v[200007], x[200007], C, sum[200007], pre[200007], ans;
int main() {
  cin >> n >> C;
  for (int i = 1; i <= n; i++) {
    cin >> x[i] >> v[i];
    sum[i] = sum[i - 1] + v[i];
    pre[i] = ((pre[i - 1]) > (sum[i] - x[i]) ? (pre[i - 1]) : (sum[i] - x[i]));
  }
  long long cnt = 0;
  long long c = C;
  for (int i = n; i >= 1; i--) {
    ans = ((ans) > (cnt + pre[i]) ? (ans) : (cnt + pre[i]));
    cnt += v[i] - 2 * (c - x[i]);
    c = x[i];
  }
  for (int i = 1; i <= n; i++) x[i] = C - x[i];
  reverse(x + 1, x + n + 1);
  reverse(v + 1, v + n + 1);
  for (int i = 1; i <= n; i++) {
    sum[i] = sum[i - 1] + v[i];
    pre[i] = ((pre[i - 1]) > (c - x[i]) ? (pre[i - 1]) : (c - x[i]));
  }
  cnt = 0;
  c = C;
  for (int i = n; i >= 1; i--) {
    ans = ((ans) > (cnt + pre[i]) ? (ans) : (cnt + pre[i]));
    cnt += v[i] - 2 * (c - x[i]);
    c = x[i];
  }
  cout << ans;
}
