program sample
    implicit none
  
    integer(8) :: i,j,m,n,x,b,c
    integer(8),allocatable :: a(:),y(:)
  
    read(*,*) n,x
    allocate(a(n))
    read(*,*)a
    m=0
    if(a(1)>x)then
        m=a(1)-x
        a(1)=x
    end if
    do i=1,n-1
        
        b=a(i)+a(i+1)
        if(b>x)then
            c=b-x
            m=m+c
            a(i+1)=a(i+1)-c
        end if
        
    end do



    write(*,*) m
  
    stop
end program sample
  

