#include <bits/stdc++.h>
using namespace std;
double EPS = 1e-9;
int INFi = 1000000005;
long long INFll = 1000000000000000005ll;
double PI = acos(-1);
int dirx[8] = {-1, 0, 0, 1, -1, -1, 1, 1};
int diry[8] = {0, 1, -1, 0, -1, 1, -1, 1};
long long MOD = 1000000007;
const int MAX_N = 100000;
long long n, c;
long long x[MAX_N], v[MAX_N];
int main() {
  cin >> n >> c;
  for (int i = 0; i < n; i++) cin >> x[i] >> v[i];
  vector<long long> sumr, suml, sumr2, suml2;
  long long sr = 0, sl = 0;
  for (int i = 0; i < n; i++) {
    sr += v[i];
    sumr.push_back(sr);
    if (2 * x[i] < c) sumr2.push_back(sr);
    sl += v[n - 1 - i];
    suml.push_back(sl);
    if (2 * (c - x[n - 1 - i]) < c) suml2.push_back(sl);
  }
  long long mr = 0, ml = 0, mr21 = 0, mr22 = 0, ml21 = 0, ml22 = 0;
  for (int i = 0; i < n; i++) {
    mr = max(sumr[i] - x[i], mr);
    ml = max(suml[i] - (c - x[n - 1 - i]), ml);
  }
  for (int i = 0; i < sumr2.size(); i++) {
    mr21 = max(sumr2[i] - x[i], mr21);
    mr22 = max(sumr2[i] - 2 * x[i], mr22);
  }
  for (int i = 0; i < suml2.size(); i++) {
    ml21 = max(suml2[i] - (c - x[n - 1 - i]), ml21);
    ml22 = max(suml2[i] - 2 * (c - x[n - 1 - i]), ml22);
  }
  cout << max(0ll, max(max(mr, ml), max(mr21 + ml22, mr22 + ml21))) << endl;
  return 0;
}
