import scala.collection.mutable

object Main extends App {
  import scala.io.StdIn._
  val n = readLine.trim.toInt
  val taxi = Array.tabulate(n){_ ⇒
    readLine.trim.split(' ').drop(1).map(_.toInt).toList
  }.reverse.toList
  implicit val queue = new mutable.PriorityQueue[Int]()
  println(
    solve(taxi)
  )
  def solve(taxi: List[List[Int]], res: Long = 0)(implicit queue: mutable.PriorityQueue[Int]): Long = {
    taxi match {
      case Nil ⇒ res
      case h::t ⇒ {
        queue.enqueue(h:_*)
        val top = queue.dequeue()
        solve(t, res + top)
      }
    }
  }
  implicit class ScopedFunc[T](val value: T){
    def let[A](func: T ⇒ A): A = func(value)
    def also(func: T ⇒ Unit): T = {
      func(value)
      value
    }
  }
}
