
fun main(args:Array<String>):Unit {
    while (true) {
        val n = readLine()!!.trim().toInt()
        if (n == 0) return
        var crues = List(n){
            Pair(it + 1, readLine()!!.trim().split(' ').drop(1).map(String::toInt))
        }
        readLine()!!.trim().split(' ').drop(1).map(String::toInt).forEach{c ->
            crues = crues.filter{
                it.second.contains(c)
            }
        }
        println(
                if (crues.size == 1) crues.first().first
                else -1
        )
    }
}
