#include <bits/stdc++.h>
using namespace std;
long long x[100005];
long long v[100005], s[100005], val, val1;
int main() {
  std::ios::sync_with_stdio(false);
  long long n, c, i, j, ans = 0;
  cin >> n >> c;
  vector<int> vis;
  vis.clear();
  vis.resize(n);
  for (i = 0; i < n; i++) {
    cin >> x[i + 1] >> v[i + 1];
    s[i + 1] = s[i] + v[i + 1];
  }
  for (i = 0; i < n; i++) {
    ans = max(ans, s[i + 1] - x[i + 1]);
    ans = max(ans, s[n] - s[i + 1] + v[i + 1] - (c - x[i + 1]));
  }
  {
    j = 1;
    i = n;
    if (i + 1 > j) {
      val = s[n] - s[i] + v[i];
      val += s[j];
      ans = max(ans, val - min(2 * (c - x[i]) + x[j], c - x[i] + 2 * x[j]));
    }
  }
  if (i > j + 1) {
    while (1) {
      if (i == j + 1) {
        break;
      }
      i--;
      val = s[n] - s[i] + v[i];
      val += s[j];
      val -= min(2 * (c - x[i]) + x[j], c - x[i] + 2 * x[j]);
      i++;
      j++;
      val1 = s[n] - s[i] + v[i];
      val1 += s[j];
      val1 -= min(2 * (c - x[i]) + x[j], c - x[i] + 2 * x[j]);
      j--;
      if (val > val1) {
        ans = max(val, ans);
        i--;
      } else {
        ans = max(ans, val1);
        j++;
      }
    }
  }
  cout << ans << endl;
}
