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

    read*, m_num
    read*, y_num

    km = 0

    do i=1,n

        if(i-1 > 0)then
            if(y_num(i-1) > 0)then
                y_num(i) = y_num(i) + y_num(i-1)
                y_num(i-1) = 0

            endif
        endif


        if(y_num(i) >= m_num(i))then
            km = km + m_num(i)
            y_num(i) = y_num(i) - m_num(i)
            m_num(i) = 0
            

        elseif(y_num(i) < m_num(i) )then
            d = m_num(i) - y_num(i)

    
            km = km + y_num(i)
            y_num(i) = 0
            m_num(i) = d
            km = km + y_num(i)
        endif
    enddo

    if(y_num(n) > m_num(n+1))then
        km = km + m_num(n+1)
    else
        km = km + y_num(n)
    endif


    print'(i0)', km
  
end program main