#include <bits/stdc++.h>
using namespace std;
const int size = 2e5 + 10;
const int INF = 1e9;
long long v[size];
long long x[size];
long long psv[size];
long long ssv[size];
long long ps[size];
long long ss[size];
int main() {
  long long n, c;
  long long ans = 0;
  cin >> n >> c;
  for (int i = 0; i < n; i++) {
    cin >> x[i] >> v[i];
    ps[i] = x[i];
    psv[i] = v[i];
    if (i > 0) {
      ps[i] += ps[i - 1] - x[i - 1];
      psv[i] += psv[i - 1];
    }
    ans = max(ans, psv[i] - ps[i]);
  }
  for (int i = n - 1; i > -1; i--) {
    ssv[i] = v[i];
    ss[i] = c - x[i];
    if (i < n - 1) {
      ssv[i] += ssv[i + 1];
      ss[i] += ss[i + 1] - (c - x[i + 1]);
    }
    ans = max(ans, ssv[i] - ss[i]);
  }
  for (int i = 0; i < n; i++) {
    for (int j = n - 1; j > i; j--) {
      ans = max(ans, psv[i] - ps[i] * 2 + ssv[j] - ss[j]);
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = n - 1; j > i; j--) {
      ans = max(ans, psv[i] - ps[i] + ssv[j] - ss[j] * 2);
    }
  }
  cout << ans;
  return 0;
}
