program test
implicit none
integer :: i,j,n
double precision :: c,x(100000),v(100000),tokei,hantokei(100000),goukei(100000)=0,saikou

read(*,*) n,c
do i = 1,n
read(*,*) x(i),v(i)
enddo

do i = 0, n

if(i == 0) then
  tokei = 0
  hantokei = 0
else
tokei = sum(v(1:i)) - x(i)
hantokei = 0
endif

do j = i+1, n
hantokei(j) = sum(v(j:n)) - (x(i) + c - x(j))
enddo

goukei(i) = tokei +  maxval(hantokei(:))

enddo

saikou = maxval(goukei(:))

do i = 1, n

tokei = sum(v(i:n)) - ( c - x(i))
hantokei = 0

do j = 1, i-1
if(j>=1) then
hantokei(j) = sum(v(1:j)) - (c - x(i) + x(j))
endif
enddo

goukei(i) = tokei +  maxval(hantokei(:))

enddo

write(*,*) max(saikou,maxval(goukei(:)))

end program