<?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 = [];
////echo "root\n";
for ($rev = -1; $rev < $n; $rev++) {
	if ($rev === -1) {
		$revConsume = 0;
		$revGain = 0;
		$revMemo[$rev + 1] = [0, 0];
	} else {
		$revConsume = ($c - $sushi[$n - 1 - $rev][0]);
		$revGain = $revMemo[$rev][1] + $sushi[$n - 1 - $rev][1];
		$revMemo[$rev + 1] = [$revConsume, $revGain];
		$revConsume *= 2;
	}
	//echo "rev:",$rev, " ", $revConsume, " ", $revGain, "\n";
	$rest = $n - $rev - 1;
	if ($rest < 1) {
		$highScore = max($highScore, $revGain - $revConsume);
		//echo "gain", $revGain , " consume", $revConsume, " now", $revGain - $revConsume, " high", $highScore,"\n";
	}
	$sumGain = $revGain;
	for ($i = 0; $i < $rest; $i++) {
		$sumConsume = $revConsume + $sushi[$i][0];
		$sumGain += $sushi[$i][1];
		$highScore = max($highScore, $sumGain - $sumConsume);
		//echo "gain", $sumGain , " consume", $sumConsume, " now", $sumGain - $sumConsume, " high", $highScore,"\n";
	}
}

//進んで戻る
//戻って進む
$sumConsume = 0;
$sumGain = 0;
$revMemo = [];
//echo "rev\n";
for ($rev = -1; $rev < $n; $rev++) {
	if ($rev === -1) {
		$revConsume = 0;
		$revGain = 0;
		$revMemo[$rev + 1] = [0, 0];
	} else {
		$revConsume = ($sushi[$rev][0]);
		$revGain = $revMemo[$rev][1] + $sushi[$rev][1];
		$revMemo[$rev + 1] = [$revConsume, $revGain];
		$revConsume *= 2;
	}
	//echo "rev:",$rev, " ", $revConsume, " ", $revGain, "\n";
	$rest = $n - $rev - 1;
	if ($rest < 1) {
		$highScore = max($highScore, $revGain - $revConsume);
		//echo "gain", $revGain , " consume", $revConsume, " now", $revGain - $revConsume, " high", $highScore,"\n";
	}
	$sumGain = $revGain;
	for ($i = 0; $i < $rest; $i++) {
		$sumConsume = $revConsume + ($c - $sushi[$n - 1 - $i][0]);
		$sumGain += $sushi[$n - 1 - $i][1];
		$highScore = max($highScore, $sumGain - $sumConsume);
		//echo "gain", $sumGain , " consume", $sumConsume, " now", $sumGain - $sumConsume, " high", $highScore,"\n";
	}
}

echo $highScore, "\n";