#include <bits/stdc++.h>
using namespace std;

#define MAX_N 100000
long long N, C, X[MAX_N], V[MAX_N];
long long R0, R1;

vector<pair<int, long long>> M;

long long solve() {
  long long acc = 0;
  M.push_back(make_pair(-1, acc));
  for(int i = 0; i < N; ++i) {
    acc += V[i]; acc -= X[i] - (i == 0 ? 0 : X[i - 1]);
    if(M.back().second < acc) M.push_back(make_pair(i, acc));
  }
  long long res = M.back().second;
  acc = 0;
  for(int i = N - 1; i >= 0; --i) {
    if(M.back().first == i) M.pop_back();
    acc += V[i]; acc -= 2 * ((C - X[i]) - (i == N - 1 ? 0 : (C - X[i + 1])));
    res = max(res, M.back().second + acc);
  }
  return res;
}

int main() {
  cin >> N >> C;
  for(int i = 0; i < N; ++i) cin >> X[i] >> V[i];
  R0 = solve();
  reverse(X, X + N); reverse(V, V + N);
  for(int i = 0; i < N; ++i) X[i] = C - X[i];
  R1 = solve();
  cout << max(R0, R1) << endl;
  return 0;
}
