#include <bits/stdc++.h>
using namespace std;
template <typename T>
ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i];
    if (i < len - 1) s << "\t";
  }
  return s;
}
template <typename T>
ostream& operator<<(ostream& s, const vector<vector<T> >& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i] << endl;
  }
  return s;
}
long long N, C;
int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> N >> C;
  vector<long long> x;
  vector<long long> v;
  for (long long i = 0; i < (N); i++) {
    long long tx, tv;
    cin >> tx >> tv;
    x.push_back(tx);
    v.push_back(tv);
  }
  long long ans = 0;
  vector<long long> ga;
  long long fa = 0, vsum = 0;
  ga.push_back(0);
  for (long long i = 0; i < (N); i++) {
    vsum += v[i];
    fa = vsum - x[i];
    ga.push_back((fa > ga[i] ? fa : ga[i]));
  }
  vsum = 0;
  for (int b = N - 1; b >= 0; b--) {
    if (b == 0) {
      ans = (ans > ga[N - 1] ? ans : ga[N - 1]);
    } else {
      fa = ga[b - 1];
    }
    vsum += v[b];
    ans = (ans > fa + vsum - (C - x[b]) * 2 ? ans : fa + vsum - (C - x[b]) * 2);
  }
  vector<long long> gb(N + 1);
  long long fb = 0;
  vsum = 0;
  gb[N] = 0;
  for (int b = N - 1; b >= 0; b--) {
    vsum += v[b];
    fb = vsum - (C - x[b]);
    gb[b] = (fb > gb[b + 1] ? fb : gb[b + 1]);
  }
  vsum = 0;
  for (int a = 0; a <= N - 1; a++) {
    if (a == N - 1) {
      fb = 0;
    } else {
      fb = gb[a + 1];
    }
    vsum += v[a];
    ans = (ans > fb + vsum - x[a] * 2 ? ans : fb + vsum - x[a] * 2);
  }
  cout << ans << endl;
  return 0;
}
