#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cstdlib>

using namespace std;

struct Sushi {
  long cal, dist;
};

int main() {
  long n, c;
  scanf("%ld %ld", &n, &c);
  Sushi sushis[10000];
  for(int i=0; i<n; ++i) {
    scanf("%ld %ld", &(sushis[i].cal), &(sushis[i].dist));
  }
  sort(sushis, sushis+n, [](const auto& s1, const auto& s2) {
    return s1.dist < s2.dist;
  });

  long lsums[10000], rsums[10000];
  long prevc=0, prevd=0, maxc=0;
  for(int i=0; i<n; ++i) {
    auto& s = sushis[i];
    long c = s.cal-(s.dist-prevd);
    maxc = max(c,maxc);
    lsums[i] = maxc;
    prevc = c;
    prevd = s.dist;
  }
  prevc = 0; prevd=c; maxc=0;
  for(int i=n-1; i>=0; --i) {
    auto & s = sushis[i];
    long c = s.cal-(prevd-s.dist);
    maxc = max(c,maxc);
    rsums[i] = maxc;
    prevc = c;
    prevd = s.dist;
  }
  long res=0;
  long pos=0;
  for(int i=0; i<n; ++i) {
    pos = sushis[i].dist;
    long a = i<n-1 ? max(0l,rsums[i+1]-pos) : 0;
    res = max(res, lsums[i]+a);
  }
  pos = c;
  for(int i=n-1; i>=0; --i) {
    pos = sushis[i].dist;
    long a = i>0 ? max(0l,lsums[i-1]-(c-pos)) : 0;
    res = max(res, rsums[i]+a);
  }
  printf("%ld\n", res);
}
