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

  auto sub_x=new long[](n+1), sub_v=new long[](n+1);
  foreach(i; 0..n){
    sub_x[i+1]=sub_x[i]+x[i];
    sub_v[i+1]=sub_v[i]+v[i];
  }
  long mx=0;
  for(int l=1; l<=n; l++)for(int r=l; r<=n; r++){
    auto cost_l=(l-1>0?x[l-1-1]:0L), cost_r=(r<n?c-x[r]:0);
    auto gain_l=sub_v[l-1]-0, gain_r=sub_v[n]-sub_v[r];
    mx=max(mx, gain_l+gain_r-(cost_l+cost_r+min(cost_l, cost_r)));
    // writeln(l, " ", r, " ", mx);
    // writeln(cost_l, " ", cost_r);
    // writeln(gain_l, " ", gain_r);
  }
  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));
}
