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

    read*, m
    read*, y

    km = 0

    do i=1,n
        c1 = min(m(i), y(i))
        c2 = min(m(i+1), y(i)-c1)

        m(i) = m(i) - c1
        m(i+1) = m(i+1) -c2
        km = km + c1+ c2
    enddo
    print'(i0)', km
  
end program main