#include <bits/stdc++.h>
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]; });
  for (int j = 0; j < n; j++) {
    int i = index[j];
    int dx = x[i] - (j ? x[index[j - 1]] : 0);
    l.push_back(l.back() - dx + v[i]);
  }
  for (int j = n; j--;) {
    int i = index[j];
    int dx = c - x[i] - (j < n - 1 ? c - x[index[j + 1]] : c);
    r.push_back(r.back() - dx + v[i]);
  }
  long long ans =
      max(*max_element(l.begin(), l.end()), *max_element(r.begin(), r.end()));
  cout << ans << endl;
}
