($N,$C)=glob<>;
($x[@x],$v[@v])=glob<>for 1..$N;
$z=0;

$x=$C;
$d=$d[$N]=0;
$s=0;
for(reverse 0..$N-1){
	$d=$d[$_]=($s+=$v[$_]-($x-$x[$_]))>$d?$s:$d;
	$z+=$-=$d-$z;
	$x=$x[$_]
}
$x=0;
$s=0;
for(0..$N-1){
	$z+=$-=($s+=$v[$_]-($x[$_]-$x)*2)+$d[$_+1]-$z;
	$x=$x[$_]
}

$x=0;
$d=$d[$N]=0;
$s=0;
for(0..$N-1){
	$d=$d[$_]=($s+=$v[$_]-($x[$_]-$x))>$d?$s:$d;
	$z+=$-=$d-$z;
	$x=$x[$_]
}
$x=$C;
$s=0;
for(reverse 0..$N-1){
	$z+=$-=($s+=$v[$_]-($x-$x[$_])*2)+$d[$_-1]-$z;
	$x=$x[$_]
}

print$z
