program sample
implicit none
integer(8) :: i,j,maxdivision
integer(8) :: x,y,count
real(8),allocatable :: a(:),b(:)

read(*,*) x,y

allocate(a(x))

read(*,*) a

count=0

do i=1,x-1
	if (a(i)+a(i+1)>y) then
	count = count+a(i)+a(i+1)-y
	a(i+1)=y-a(i)
		if (a(i+1)<0) then
		a(i)=a(i)+a(i+1)
		a(i+1) = 0
		end if
	end if
end do

write(*,*) count
!write(*,*) a

end program sample