#include <bits/stdc++.h>
using namespace std;
template <typename T>
ostream& operator<<(ostream& os, vector<T>& v) {
  for (int i = 0; i < (v.size()); i++) {
    os << v[i] << (i == v.size() - 1 ? "" : " ");
  }
  return os;
}
template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
  for (T& x : v) {
    is >> x;
  }
  return is;
}
vector<long long> getSum(vector<long long> v) {
  reverse((v).begin(), (v).end());
  vector<long long> res(v.size() + 1);
  for (int i = 0; i < (v.size()); i++) {
    res[i + 1] = res[i] + v[i];
  }
  return res;
}
const long long INF = (1LL << 60);
int main() {
  int n;
  long long c;
  cin >> n >> c;
  vector<long long> x(n), v(n);
  for (int i = 0; i < (n); i++) {
    cin >> x[i] >> v[i];
  }
  long long last = x.back();
  for (int i = n - 1; i >= 1; i--) {
    x[i] = x[i] - x[i - 1];
  }
  vector<long long> fx(n + 1, 0), bx;
  for (int i = 0; i < (n); i++) {
    fx[i + 1] = fx[i] + x[i];
  }
  vector<long long> cx(n);
  for (int i = 0; i < (n - 1); i++) {
    cx[i] = x[i + 1];
  }
  cx[n - 1] = c - last;
  bx = getSum(cx);
  vector<long long> fp(n + 1, 0), bp;
  for (int i = 0; i < (n); i++) {
    fp[i + 1] = fp[i] + v[i];
  }
  bp = getSum(v);
  long long ans = 0;
  for (int i = 0; i < (n); i++) {
    ans = max(ans, fp[i + 1] - fx[i + 1]);
  }
  for (int i = 0; i < (n); i++) {
    ans = max(ans, bp[i + 1] - bx[i + 1]);
  }
  vector<long long> fr(n), br(n);
  for (int i = 0; i < (n); i++) {
    fr[i] = fp[i + 1] - fx[i + 1] * 2;
  }
  for (int i = 0; i < (n); i++) {
    br[i] = bp[i + 1] - bx[i + 1] * 2;
  }
  vector<long long> fmax(n, -INF), bmax(n, -INF);
  for (int i = 0; i < (n); i++) {
    fmax[i] = max(fmax[max(i - 1, 0)], fp[i + 1] - fx[i + 1]);
  }
  for (int i = 0; i < (n); i++) {
    bmax[i] = max(bmax[max(i - 1, 0)], bp[i + 1] - bx[i + 1]);
  }
  if (n - 2 >= 0) {
    for (int i = 0; i < (n); i++) {
      ans = max(ans, fr[i] + bmax[n - i - 2]);
    }
    for (int i = 0; i < (n); i++) {
      ans = max(ans, br[i] + fmax[n - i - 2]);
    }
  }
  cout << ans << endl;
}
