#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 1;
int n, v[N];
long long c, cs[N], x[N], rem[N];
int main() {
  scanf("%d%lld", &n, &c);
  for (int i = 0; i < n; i++) scanf("%lld%d", x + i, v + i);
  long long last = 0, bad = 0, ans = 0, sum = 0;
  for (int i = 0; i < n; i++) {
    bad = x[i];
    last = x[i];
    sum += v[i];
    ans = max(ans, sum - bad);
    cs[i] = sum - bad - bad;
    rem[i] = bad;
  }
  for (int i = 1; i < n; i++) {
    if (cs[i] < cs[i - 1]) {
      cs[i] = cs[i - 1];
      rem[i] = rem[i - 1];
    } else if (cs[i] == cs[i - 1])
      rem[i] = max(rem[i], rem[i - 1]);
  }
  last = c;
  bad = 0;
  sum = 0;
  for (int i = n - 1; i + 1; i--) {
    bad = last - x[i];
    sum += v[i];
    ans = max(ans, sum - bad);
    ans = max(ans, sum - bad + (i ? cs[i - 1] : 0));
    ans = max(ans, sum - bad - bad + (i ? cs[i - 1] + rem[i] : 0));
  }
  printf("%lld\n", ans);
}
