<?php
fscanf(STDIN, "%d %d", $n, $c);

$sushi = [];
for ($i = 0; $i < $n; $i++) {
	fscanf(STDIN, "%d %d", $x, $y);
	$sushi[] = [$x, $y];
}

//戻って進む
$sumConsume = 0;
$sumGain = 0;
$highScore = 0;
$revMemo = [[0, 0]];
$gainMemo = [[0, 0]];

for ($rev = 0; $rev < $n; $rev++) {
	$revConsume = $c - $sushi[$n - 1 - $rev][0];
	$revGain = $revMemo[$rev][1] + $sushi[$n - 1 - $rev][1];
	$revMemo[$rev + 1] = [$revConsume, $revGain];
}
for ($i = 0; $i < $n; $i++) {
	$consume = $sushi[$i][0];
	$gain = $gainMemo[$i][1] + $sushi[$i][1];
	$gainMemo[$i + 1] = [$consume, $gain];
}
for ($rev = 0; $rev < $n; $rev++) {
	$rest = $n - $rev;
	if ($rest < 1) {
		$highScore = max($highScore, $revMemo[$rev][1] - $revMemo[$rev][0] * 2);
	}
	for ($i = 0; $i < $rest; $i++) {
		$highScore = max($highScore, $revMemo[$rev][1] + $gainMemo[$i][1]
			- $revMemo[$rev][0] * 2 - $gainMemo[$i][0]);
	}
}
for ($rev = 0; $rev < $n; $rev++) {
	$rest = $n - $rev;
	if ($rest < 1) {
		$highScore = max($highScore, $gainMemo[$rev][1] - $gainMemo[$rev][0] * 2);
	}
	for ($i = 0; $i < $rest; $i++) {
		$highScore = max($highScore, $gainMemo[$rev][1] + $revMemo[$i][1]
			- $gainMemo[$rev][0] * 2 - $revMemo[$i][0]);
	}
}

//var_dump($revMemo, $gainMemo);
echo $highScore, "\n";