#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  long long c;
  cin >> n >> c;
  vector<long long> x(n + 1), v(n + 1);
  vector<long long> s(n + 1);
  for (int i = 1; i <= n; i++) {
    cin >> x[i] >> v[i];
    s[i] = s[i - 1] + v[i];
  }
  long long ans = 0;
  for (int i = 0; i <= n; i++) {
    ans = max(ans, s[i] - x[i]);
    ans = max(ans, s[n - i] - (c - x[i]));
  }
  for (int i = 0; i <= n; i++) {
    {
      int l = i + 1;
      int r = n;
      while (r - l >= 10) {
        int x0 = (l * 2 + r) / 3;
        int x1 = (l + r * 2) / 3;
        long long v0 = s[i] + (s[n] - s[x0 - 1]) - x[i] * 2 - (c - x[x0]);
        long long v1 = s[i] + (s[n] - s[x1 - 1]) - x[i] * 2 - (c - x[x1]);
        if (v0 < v1) {
          l = x0;
        } else {
          r = x1;
        }
      }
      for (int j = l; j <= r; j++) {
        ans = max(ans, s[i] + (s[n] - s[j - 1]) - x[i] * 2 - (c - x[j]));
      }
    }
    {
      int l = i + 1;
      int r = n;
      while (r - l >= 10) {
        int x0 = (l * 2 + r) / 3;
        int x1 = (l + r * 2) / 3;
        long long v0 = s[i] + (s[n] - s[x0 - 1]) - x[i] - (c - x[x0]) * 2;
        long long v1 = s[i] + (s[n] - s[x1 - 1]) - x[i] - (c - x[x1]) * 2;
        if (v0 < v1) {
          l = x0;
        } else {
          r = x1;
        }
      }
      for (int j = l; j <= r; j++) {
        ans = max(ans, s[i] + (s[n] - s[j - 1]) - x[i] - (c - x[j]) * 2);
      }
    }
  }
  cout << ans << endl;
}
