program answer
  implicit none
  integer(8) :: i, N
  integer, allocatable :: A(:), B(:), ato(:)
  read(*,*) N
  allocate(A(N+1),B(N),ato(N+1))
  read(*,*) A
  read(*,*) B
  ato=A
  do i = 1, N
     if(ato(i)<=B(i)) then
        if(ato(i+1)+ato(i)<=B(i)) then
           ato(i)=0
           ato(i+1)=0
         else
           ato(i+1)=ato(i+1)-(B(i)-ato(i))
           ato(i)=0
        end if
     else
        ato(i)=ato(i)-B(i)
     end if
  end do

  write(*,*) sum(A)-sum(ato)
  stop
 end program answer
