program main
  implicit none
  integer(8) :: n, i, res, kill
  integer(8), allocatable :: a(:), b(:)
  read (*, *) n
  allocate (a(n + 1), b(n))
  read (*, *) a
  read (*, *) b
  res = 0
  do i = 1, n
    kill = min(a(i), b(i))
    res = res + kill
    b(i) = b(i) - kill
    kill = min(a(i + 1), b(i))
    res = res + kill
    a(i + 1) = a(i + 1) - kill
  end do
  write (*, "(i0)") res
end program main
