n = gets
as = gets.split.map(&:to_i)
bs = gets.split.map(&:to_i)

count = 0
reserve = 0
bs.each_with_index do |b, i|
  if reserve > 0
    as[i] -= reserve
    count += reserve
    reserve = 0
  end
  c = as[i] - b
  if c >= 0
    count += b
  else
    count += as[i]
    reserve = -c
  end
end

l = [as.last, reserve].min
p count + l
