import scala.io.StdIn.{readLine,readInt}
import scala.collection.mutable.ArrayBuffer

object Main {
  def main(args:Array[String]) = {
    val n = readInt
    val b = new ArrayBuffer[Int]
    val g = for(i<-0 until n) yield {
      readLine.trim.split(" ").map(_.toInt)
    }

    var v = 0
    var total = 0
    b += v

    while(b.length < g.length) {
      var min = Int.MaxValue
      v = 0
      for(e <- b) {
        val list = for(i<-0 until g(e).length if !b.contains(i) && g(e)(i) != -1) yield (g(e)(i),i)
        if(list.length > 0) {
          val listMin = list.min
          if(listMin._1<min) {
            min = listMin._1
            v = listMin._2
          }
        }
      }
      total += min
      b += v
    }
    println(total)
  }
}