integer(16) N,C
integer(16),allocatable::x(:),v(:),ccx(:),ccv(:),OA2(:),OB2(:)
integer(16) i
integer(16) ans
read*,N,C
allocate(x(N),v(0:N),ccx(N),ccv(0:N))
v(0)=0
do i=1,N
  read*,x(i),v(i)
  v(i)=v(i)+v(i-1)
end do
ccv(0)=0
do i=1,N
  ccx(i)=C-x(N-i+1)
  ccv(i)=V(N)-V(N-i+1-1)
end do

allocate(OA2(0:N),OB2(0:N))
OA2(0)=0
do i=1,N
  OA2(i)=max(OA2(i-1),v(i)-x(i)*2)
end do

OB2(0)=0
do i=1,N
  OB2(i)=max(OB2(i-1),ccv(i)-ccx(i)*2)
end do

ans=0
do i=1,N
  ans=max(ans,ccv(i)-ccx(i)+OA2(N-i))
end do
do i=1,N
  ans=max(ans,v(i)-x(i)+OB2(N-i))
end do

print"(i0)",ans
end