#include <bits/stdc++.h>
using namespace std;
long long n, c, dist[101010], x[101010], v[101010], srv[101010], sv[101010],
    ans = 0, ans1 = 0;
;
vector<pair<long long, long long> > adj[202020];
bool vis[101010];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> c;
  for (int i = 1; i <= n; i++) {
    cin >> x[i] >> v[i];
    sv[i] += sv[i - 1] + v[i];
  }
  for (int i = n; i >= 1; i--) {
    srv[i] += srv[i + 1] + v[i];
  }
  long long mx = 0;
  long long mxi = 0;
  for (int i = 1; i <= n; i++) {
    if (sv[i] - x[i] >= 0) {
      if (sv[i] - x[i] > mx) {
        mxi = i;
        mx = sv[i] - x[i];
      }
    }
  }
  ans = mx;
  mx = 0;
  for (int i = n; i >= mxi + 1; i--) {
    if (srv[i] - (c - x[i] + x[mxi]) >= 0) {
      if (srv[i] - (c - x[i] + (x[mxi])) > mx) {
        mx = srv[i] - (c - x[i] + x[mxi]);
      }
    }
  }
  ans += mx;
  mx = 0;
  mxi = 0;
  for (int i = n; i >= 1; i--) {
    if (srv[i] - (c - x[i]) >= 0) {
      if ((srv[i] - (c - x[i])) > mx) {
        mxi = i;
        mx = srv[i] - (c - x[i]);
      }
    }
  }
  ans1 = mx;
  mx = 0;
  for (int i = 1; i <= mxi - 1; i++) {
    if (sv[i] - (c - x[i] + x[mxi]) >= 0) {
      if (sv[i] - (c - x[i] + (x[mxi])) > mx) {
        mx = srv[i] - (c - x[i] + x[mxi]);
      }
    }
  }
  ans1 += mx;
  cout << max(ans1, ans) << endl;
  return 0;
}
