program test
  implicit none
  integer :: n, flag, i, k, j, sum
  integer, dimension ( : ), allocatable :: a, b
  integer, dimension ( :, : ), allocatable :: p  

  read ( unit = *, fmt = * ) n

  allocate ( a ( 1 : n + 1 ) )
  allocate ( b ( 1 : n + 1 ) )
  allocate ( p ( 1 : n, 0 : 1 ) )  

  a ( : ) = 0
  b ( : ) = 0  
  
  read ( unit = *, fmt = * ) a ( 1 : n + 1 )
  read ( unit = *, fmt = * ) b ( 1 : n )  

  p ( 1, 0 ) = min ( a ( 1 ), b ( 1 ) )

  sum = p ( 1, 0 )
  
  do i = 1, n

     p ( i, 1 ) = min ( a ( i + 1 ), b ( i ) - p ( i, 0 ) )

     p ( i + 1, 0 ) = min ( a ( i + 1 ) - p ( i, 1 ), b ( i + 1 ) )

     sum = sum + p ( i, 1 ) + p ( i + 1, 0 )
     
  end do

  write ( unit = *, fmt = '(i0)')  sum
  
end program test
