#include <bits/stdc++.h>
using namespace std;
template <class T>
void chmin(T& a, T const& b) {
  if (b < a) a = b;
}
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
using ll = long long;
const ll mod = LLONG_MAX;
ll x[112345], v[112345];
ll d[112345], cd[112345];
bool eat[112345];
signed main() {
  long long n, c;
  cin >> n >> c;
  ll mans = 0;
  ll ans = 0;
  long long prev_x = 0;
  long long prev_v = 0;
  for (long long i = 0; i < n; i++) {
    cin >> x[i] >> v[i];
  }
  for (long long i = 0; i < n; i++) {
    ans += -(x[i] - prev_x);
    ans += v[i];
    prev_x = x[i];
    prev_v = v[i];
    mans = max(ans, mans);
  }
  cerr << "mans"
       << "=" << mans << endl;
  prev_x = c;
  ans = 0;
  for (long long i = n - 1; i >= 0; i--) {
    ans += (x[i] - prev_x);
    ans += v[i];
    prev_x = x[i];
    prev_v = v[i];
    mans = max(ans, mans);
  }
  cerr << "mans"
       << "=" << mans << endl;
  prev_x = 0;
  ans = 0;
  for (long long i = 0; i < n; i++) {
    d[i] += -(x[i] - prev_x) * 2;
    d[i] += v[i];
    prev_x = x[i];
  }
  long long idx = 0;
  while (1) {
    if (idx >= n || d[idx] < 0) break;
    eat[idx] = true;
    ans += d[idx];
    idx++;
  }
  prev_x = c;
  for (long long i = n - 1; i >= 0; i--) {
    if (eat[i]) break;
    ans += (x[i] - prev_x);
    ans += v[i];
    prev_x = x[i];
    prev_v = v[i];
    mans = max(ans, mans);
  }
  cerr << "t->anti" << endl;
  cerr << "mans"
       << "=" << mans << endl;
  for (long long i = 0; i < n; i++) eat[i] = false;
  ans = 0;
  prev_x = c;
  for (long long i = n - 1; i >= 0; i--) {
    cd[i] += (x[i] - prev_x) * 2;
    cd[i] += v[i];
    prev_x = x[i];
  }
  idx = n - 1;
  while (1) {
    if (idx <= 0 || cd[idx] < 0) break;
    eat[idx] = true;
    ans += cd[idx];
    idx--;
  }
  prev_x = 0;
  for (long long i = 0; i < n; i++) {
    if (eat[i]) break;
    ans += -(x[i] - prev_x);
    ans += v[i];
    prev_x = x[i];
    mans = max(ans, mans);
  }
  cout << mans << endl;
}
