program main
    implicit none
    integer n, d
    integer km, i
    integer warn(2)
    integer, allocatable :: m(:), y(:)
    read*,n
    allocate(m(n+1), y(n))

    read*, m
    read*, y

    km = 0

    do i=1,n
        d = y(i) - m(i)
        if(d>=0)then
            km = km + m(i)
            y(i) = y(i) - m(i)
            m(i) = 0

        else
            km = km + y(i)
            m(i) = m(i) - y(i)
            y(i) = 0
        endif

        if ( y(i)>0 .and. i+1 <= n) then
            if(y(i) > m(i+1))then
                km = km + m(i+1) 
                y(i) = y(i) - m(i+i)
                m(i+1) = 0
            
            else
                km =  km + y(i)
                m(i+1) = m(i+1) - y(i)
                y(i) = 0
            endif
            
        end if
    enddo
    print'(i0)', km
  
end program main