
class Person(val size:Int){
    val history:Array<Boolean> = Array(size){false}
    val isCollectMap:Boolean
        get() = history.size == history.count{it}
}
fun main(args:Array<String>):Unit{
    while(true){
        val n = readLine()!!.toInt()
        if (n == 0) return
        val persons = Array(n){
            Person(n)
        }
        for (i in 0 until n) persons[i].history[i] = true
        val schedules = Array(n){
            Pair(it, readLine()!!.split(' ').drop(1).map(String::toInt))
        }
        dateloop@for (date in 1 .. 30){
            val s = schedules.filter{(_, schedule) -> schedule.contains(date)}.map{persons[it.first]}
            (0 until n).map{
                s.fold(false){b, p -> b || p.history[it]}
            }.withIndex().filter{it.value}.forEach {i -> s.forEach {p -> p.history[i.index] = true  } }
            if (s.any{it.isCollectMap}){
                println(date)
                break@dateloop
            }
        }
        if (persons.none{it.isCollectMap})
            println(-1)
    }
}
