program test
implicit none
integer :: i,j,n
integer(8) :: c,x(100001),v(100001),profit(100001)=0,profit2(100001)=0,max_value=0,max_value2=0

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

!clockwise_start

do j = n, 1, -1
  profit(j) = sum(v(j:n))-(c-x(j))
  if(j < n) profit(j) = max(profit(j),profit(j+1))
enddo

do i = 1, n
  profit2(i) = sum(v(1:i)) - 2 * x(i) + max(x(i),profit(i+1))
  max_value = max(max_value,profit2(i))
  enddo

!counterclockwise_start

do i = 1, n
  profit(i) = sum(v(1:i))-x(i)
  if(i >= 2) profit(i) = max(profit(i),profit(i-1))
enddo

do j = 1, n
  profit2(j) = sum(v(j:n))- 2 * (c-x(j)) + max((c-x(j)),profit(j-1))
  max_value2 = max(max_value2,profit2(j))
enddo

write(*,*) max(max_value,max_value2)

end program