import io.StdIn._

object Main extends App {
  readInt
  val a = readLine.split(" ").map(_.toLong).toList
  val b = readLine.split(" ").map(_.toLong).toList

  def solve(a: List[Long], b: List[Long], res: Long): Long = b match {
    case Nil => res
    case x :: xs if x < a.head => solve(a.tail, xs, res + x)
    case x :: xs => {
      val rest = math.max(0, a.tail.head - (x - a.head))
      val m = math.min(x, a.head + a.tail.head)
      solve(rest :: a.tail.tail, xs, res + m)
    }
  }
  println(solve(a,b,0))
}
