sub max{$_[$_[1]>$_[0]]}
($N,$D)=glob<>;
@K=-inf;
for(1..$N){
	($T,$K)=glob<>;
	$T[$_]=$T+max($T[$_-1],$K[$_-1]-$D);
	$K[$_]=$K+max($K[$_-1],$T[$_-1]-$D);
}
print max($T[$N],$K[$N])