#include <bits/stdc++.h>
using namespace std;
long long x[900000], v[900000];
pair<long long, long long> v1[900000], v2[900000], back1[900000], back2[900000];
long long max1[900000], max2[900000];
int main() {
  long long n, c;
  scanf("%lld%lld", &n, &c);
  for (int i = 1; i <= n; i++) scanf("%lld%lld", &x[i], &v[i]);
  for (int i = 1; i <= n; i++) {
    v1[i].first = v1[i - 1].first - x[i] + x[i - 1] + v[i];
    v1[i].second = v1[i].first - x[i];
  }
  x[n + 1] = c;
  for (int i = n; i >= 1; i--) {
    v2[i].first = v[i] + v2[i + 1].first - x[i + 1] + x[i];
    v2[i].second = v2[i].first - c + x[i];
  }
  for (int j = 0; j <= n + 1; j++) {
    max1[j] = max(max1[j - 1], v1[j].first);
    max2[j] = max(max2[j - 1], v1[j].second);
  }
  long long ans = 0;
  for (int i = 0; i <= n; i++) {
    ans = max(ans, max(v1[i].second + max1[i], v1[i].first + max2[i]));
  }
  printf("%lld\n", ans);
}
