import scala.collection.mutable
import scala.io.StdIn._

case class Edge(to: Int, cost: Int)

object Main extends App {
  val n = readInt()
  val d = mutable.Seq.fill(n)(Seq.empty[Edge])

  for (i <- 0 until n) {
    val costs = readLine().tail.split(" ")
    for (j <- costs.indices) {
      d(i) :+= Edge(j, costs(j).toInt)
    }
  }

  val parents = mutable.Seq.fill(n)(-1)
  val distances = mutable.Seq.fill(n)(Int.MaxValue)
  distances(0) = 0
  val que = mutable.PriorityQueue(Edge(0, 0))(Ordering.by((e: Edge) => e.cost).reverse)

  while (que.nonEmpty) {
    val edge = que.dequeue()
    if (distances(edge.to) >= edge.cost) {
      for (e <- d(edge.to)) {
        if (e.cost != -1 &&
          distances(e.to) > distances(edge.to) + e.cost) {
          distances(e.to) = distances(edge.to) + e.cost
          parents(e.to) = edge.to
          que.enqueue(e)
        }
      }
    }
  }

  var sum = 0
  for (i <- parents.tail.indices) {
    sum += d(parents(i + 1))(i + 1).cost
  }

  println(sum)
}