N = gets.to_i
A = gets.chomp.split(" ").map(&:to_i)
B = gets.chomp.split(" ").map(&:to_i)

def DefeatMonsters(i, j)
  if A[i] > B[j] then
    tmp = B[j]
    A[i] -= tmp
    B[j] = 0
    tmp
  else
    tmp = A[i]
    A[i] = 0
    B[j] -= tmp
    tmp
  end
end

ans = 0
N.times{|i|
  ans += DefeatMonsters(i, i)
  ans += DefeatMonsters(i + 1, i) if B[i] > 0
}

puts ans
