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

x(0) = 0
v(0) = 0

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

do i = 0, n

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

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

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

enddo

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

end program