#include <bits/stdc++.h>
using namespace std;
double const pi = 3.1415926535;
int const mod = 1000000007;
int const inf = 2147483647;
long long x[114514], v[114514];
long long ans;
long long sum_clock[114514];
long long sum_rclock[114514];
int main() {
  long long n, c;
  cin >> n >> c;
  for (int i = 1; i <= n; i++) cin >> x[i] >> v[i];
  for (int i = 1; i <= n; i++) {
    sum_clock[i] = sum_clock[i - 1] + v[i];
    ans = max(ans, sum_clock[i] - x[i]);
  }
  for (int i = n; i >= 1; i--) {
    sum_rclock[i] = sum_rclock[i + 1] + v[i];
    ans = max(ans, sum_rclock[i] - c + x[i]);
  }
  for (int i = 1; i <= n - 2; i++) {
    for (int j = n; j >= i + 2; j--) {
      if (x[i] > c - x[j])
        ans = max(ans, sum_clock[i] + sum_rclock[j] - 2 * (c - x[j]) - x[i]);
      else
        ans = max(ans, sum_clock[i] + sum_rclock[j] - 2 * x[i] - c + x[j]);
    }
  }
  cout << ans << endl;
  return 0;
}
