#include <bits/stdc++.h>
using namespace std;
inline void prep() {
  cin.tie(0);
  cin.sync_with_stdio(0);
}
const int mod = (int)1e9 + 7;
const int MX = (int)2e5 + 1;
int main() {
  prep();
  int n;
  cin >> n;
  long long c;
  cin >> c;
  vector<pair<long long, long long>> v(n + 1);
  vector<long long> fwacc(n + 1), bcacc(n + 1);
  v[0] = make_pair(0, 0);
  for (int i = 1; i <= n; ++i) {
    cin >> v[i].first >> v[i].second;
  }
  for (int i = 1; i <= n; ++i) {
    fwacc[i] = v[i].second + fwacc[i - 1];
  }
  bcacc[n] = v[n].second;
  for (int i = n - 1; i > 0; --i) {
    bcacc[i] += bcacc[i + 1] + v[i].second;
  }
  long long res = 0;
  vector<int> bst_idx(n + 1);
  vector<int> bst_idx2(n + 1);
  int idx = 0;
  long long bst = 0;
  for (int i = 1; i <= n; ++i) {
    bst = fwacc[i] - v[i].first;
    if (bst > res) {
      res = bst;
      idx = i;
    }
    bst_idx[i] = idx;
  }
  long long cur = 0;
  bst = 0;
  idx = n;
  for (int i = n; i > 0; --i) {
    cur = bcacc[i] - (c - v[i].first);
    if (cur > bst) {
      bst = cur;
      idx = i;
    }
    bst_idx2[i] = idx;
  }
  res = max(res, bst);
  for (int bc_idx = n; bc_idx > 0; --bc_idx) {
    int fw_idx = bst_idx[bc_idx - 1];
    long long dist_bc = c - v[bc_idx].first;
    long long dist_fw = v[fw_idx].first;
    res = max(res, bcacc[bc_idx] + fwacc[fw_idx] -
                       (2 * min(dist_fw, dist_bc) + max(dist_fw, dist_bc)));
  }
  for (int fw_idx = 1; fw_idx <= n; ++fw_idx) {
    int bc_idx = bst_idx2[n - fw_idx + 1];
    long long dist_fw = v[fw_idx].first;
    long long dist_bc = c - v[bc_idx].first;
    res = max(res, bcacc[bc_idx] + fwacc[fw_idx] -
                       (2 * min(dist_fw, dist_bc) + max(dist_fw, dist_bc)));
  }
  cout << res << endl;
  return 0;
}
