void main(){
  import std.stdio, std.string, std.conv, std.algorithm;
  
  int n; long c; rd(n, c);
  auto x=new long[](n), v=new long[](n);
  foreach(i; 0..n) rd(x[i], v[i]);

  import std.exception;
  enforce(n<=100);

  x=0L~x~c;
  v=0L~v~0L;

  long mx=0, inf=2e18.to!(long);

  auto a=new long[](n+2); // a[i]:=[i, n+1]
  fill(a, -inf);
  a[n+1]=0;
  for(auto r=n, s=0L; r>0; r--){
    s+=v[r];
    a[r]=max(a[r+1], s-(c-x[r]));
  }
  // writeln(a);
  for(auto l=0, s=0L; l<=n; l++){
    s+=v[l];
    mx=max(mx, (s-x[l]*2)+a[l+1]);
  }
  auto b=new long[](n+2); // b[i]:=[0, i]
  fill(b, -inf);
  b[0]=0;
  for(auto l=1, s=0L; l<=n; l++){
    s+=v[l];
    b[l]=max(b[l-1], s-x[l]);
  }
  // writeln(b);
  for(auto r=n+1, s=0L; r>0; r--){
    s+=v[r];
    mx=max(mx, (s-(c-x[r])*2+b[r-1]));
  }

  long tot=reduce!"a+b"(0L, v);
  for(int i=0; i<=n; i++){
    long cl=x[i], cr=c-x[i+1];
    long cost=cl+cr+min(cl, cr);
    mx=max(mx, tot-cost);
  }
  writeln(mx);
}

void rd(T...)(ref T x){
  import std.stdio, std.string, std.conv;
  auto l=readln.split;
  assert(l.length==x.length);
  foreach(i, ref e; x) e=l[i].to!(typeof(e));
}
