#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>

using namespace std;
int main() {
  long long n, c;
  vector<long long> x, v, index;
  vector<long long> l(1, 0), r(1, 0);
  cin >> n >> c;
  for (int i = 0; i < n; i++) {
    int xi, vi;
    cin >> xi >> vi;
    x.push_back(xi);
    v.push_back(vi);
    index.push_back(i);
  }
  sort(index.begin(), index.end(), [&](int i, int j) -> int {
    return x[i] < x[j];
  });
  // clockwise
  for (int j = 0; j < n; j++) {
    int i = index[j];
    l.push_back(l.back() - x[i] + v[i]);
  }
  // anticlockwise
  for (int j = n; j--;) {
    int i = index[j];
    r.push_back(r.back() - (c - x[i]) + v[i]);
  }
  long long ans = max(*max_element(l.begin(), l.end()), *max_element(r.begin(), r.end()))
  cout << ans << endl;
}
