#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000000;
const long long int LINF = (long long int)4000000000000000000;
const long long int MOD = (long long int)1000000007;
const double PI = acos(1.0);
const int limit = 100010;
int main() {
  long long int n, c;
  cin >> n >> c;
  map<long long int, long long int> x, v;
  for (long long int i = 1; i < (long long int)(n + 1); i++)
    cin >> x[i] >> v[i];
  x[n + 1] = c;
  map<long long int, long long int> vsum_right, vsum_left;
  for (long long int i = 1; i < (long long int)(n + 1 + 1); i++)
    vsum_right[i] = vsum_right[i - 1] + v[i];
  for (long long int i = 1; i < (long long int)(n + 1 + 1); i++)
    vsum_left[i] = vsum_right[n] - vsum_right[n - i];
  map<long long int, long long int> f;
  map<long long int, pair<long long int, long long int> > g;
  for (long long int i = 1; i < (long long int)(n + 1 + 1); i++)
    f[i] = vsum_right[i] - x[i];
  for (long long int i = 0; i < (long long int)(n + 2); i++) {
    if (g[i - 1].first >= f[i])
      g[i] = g[i - 1];
    else
      g[i] = make_pair(f[i], i);
  }
  long long int Max = 0;
  for (long long int xb_l = 0; xb_l < (long long int)(n + 2); xb_l++) {
    long long int xb_r = n - xb_l + 1;
    long long int oa = g[xb_r - 1].first;
    long long int ob = vsum_left[xb_l] - (c - x[xb_r]);
    Max = max({Max, oa + ob - (c - x[xb_r]), oa + ob - x[g[xb_r - 1].second]});
  }
  cout << Max << endl;
  return 0;
}
