Uses math;
var
	ans,L,R,Lmax,Rmax,c:int64;
	n,i:Longint;
	x,v:array[1..100000]of Longint;
begin
	read(n,c);
	for i:=1 to n do begin
		read(x[i],v[i]);
		inc(L,v[i]);
	end;
	ans:=L-x[n];
	for i:=n downto 1 do begin
		dec(L,v[i]);
		inc(R,v[i]);
		Rmax:=Max(Rmax,R-(c-x[i]));
		if i>1 then ans:=Max(ans,L-x[i-1]*2+Rmax)else ans:=Max(ans,Rmax);
	end;
	for i:=1 to n do begin
		inc(L,v[i]);
		dec(R,v[i]);
		Lmax:=Max(Lmax,L-x[i]);
		if i<n then ans:=Max(ans,R-(c-x[i+1])*2+Lmax)else ans:=Max(ans,Lmax);
	end;
	writeln(ans);
end.
