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 tot=reduce!"a+b"(0L, v), mx=0;
  for(int l=1; l<=n; l++)for(int r=l; r<=n; r++){
    long cl=x[l-1], cr=c-x[r+1],
         cost=cl+cr+min(cl, cr);
    long gain=tot; // -reduce!"a+b"(0L, v[l..(r+1)]);
    for(int k=l; k<=r; k++) gain-=v[k];
    mx=max(mx, gain-cost);
    // writeln(l, " ", r, " ", mx);
  }

  writeln(max(mx, tot-(c-min(x[1], c-x[n]))));
}

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));
}
