#include <bits/stdc++.h>
using namespace std;
struct Grid {
  long long x, v;
  bool operator<(const Grid& another) const {
    if (x != another.x) return x < another.x;
  }
};
int n;
long long c;
vector<Grid> in;
vector<long long> r;
vector<long long> l;
vector<long long> mr;
vector<long long> ml;
int main() {
  cin >> n >> c;
  for (int i = 0; i < n; i++) {
    long long inx, inv;
    cin >> inx >> inv;
    Grid ing;
    ing.x = inx;
    ing.v = inv;
    in.push_back(ing);
  }
  sort(in.begin(), in.end());
  vector<Grid> root = in;
  long long vr = in[0].v - in[0].x;
  r.push_back(vr);
  long long zero = 0;
  mr.push_back(max(vr, zero));
  for (int i = 1; i < n; i++) {
    long long vr = in[i].v - (in[i].x - in[i - 1].x) + r[i - 1];
    r.push_back(vr);
    mr.push_back(max(vr, r[i - 1]));
  }
  reverse(in.begin(), in.end());
  long long vl = in[0].v - (c - in[0].x);
  l.push_back(vl);
  ml.push_back(max(vl, zero));
  for (int i = 1; i < n; i++) {
    long long vl = in[i].v - (in[i - 1].x - in[i].x) + l[i - 1];
    l.push_back(vl);
    ml.push_back(max(vl, l[i - 1]));
  }
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    long long cal = r[i] - root[i].x + ml[n - i - 2];
    ans = max(cal, ans);
  }
  for (int i = 0; i < n; i++) {
    long long cal = l[i] - in[i].x + mr[n - i - 2];
    ans = max(cal, ans);
  }
  cout << ans << endl;
  return 0;
}
