PROGRAM ATCODER

implicit none
integer(16) :: n,x,i,ans=0
integer(16),allocatable :: a(:),b(:,:)

read(*,*) n,x
allocate(a(n),b(n-1,n))
read(*,*) (a(i), i=1,n)

do i = 2,n
  b(i-1,i) = a(i) + a(i-1)
end do

do i = 1,n-2
  if ( b(i,i+1) > x ) then
    ans = ans + b(i,i+1) - x
    b(i+1,i+2) = b(i+1,i+2) - (b(i,i+1) - x)
  end if
end do

if ( b(n-1,n) > x ) then
  ans = ans + b(n-1,n) - x
end if

write(*,'(i0)') ans

contains
!!!!!! サブルーチンは↓
!!!!!!

END PROGRAM ATCODER
