object Main extends App {
  import scala.io.StdIn._



  val n = readInt
  val wise = readLine.trim.split(' ').map(_.toInt == 0).zip(readLine.trim.split(' ').map(_.toInt)).map(it ⇒ Wise(it._1, it._2))
  var min = Int.MaxValue
  for (w ← wise.permutations){
    var sum = 0
    for (i ← w.indices){
      if (w(i).right) {
        if (!w((i + 1) % n).right) {
          sum += w(i).hate
          sum += w((i + 1) % n).hate
        }
      }
    }
    if (min > sum) min = sum
  }
  println(min)
  case class Wise(right: Boolean, hate: Int)
}

