gets # n = gets.to_i
a = gets.split(' ').map(&:to_i)
b = gets.split(' ').map(&:to_i) << 0

result = a.zip(b).reduce(
  total_killed: 0,
  remaining_kill_ability: 0
) do |acm, (ai, bi)|
  # the previous saver kill all monsters at the current city
  if ai <= acm[:remaining_kill_ability]
    next {
      total_killed: acm[:total_killed] + ai,
      remaining_kill_ability: bi
    }
  end

  # the previous saver kill monsters
  prev_killed = acm[:remaining_kill_ability]
  remaining_monster_count = ai - prev_killed
  # the current saver kill remaining monsters
  current_killed = [remaining_monster_count, bi].min
  {
    total_killed: acm[:total_killed] + prev_killed + current_killed,
    remaining_kill_ability: bi - current_killed
  }
end

puts result[:total_killed]
