loop do
    n = gets.to_i
    break if n == 0
    p = n.times.map{gets.split.map(&:to_i)}.map{|pp| pp[1...pp.size]}
    k = gets.split.map(&:to_i)
    p p.select{|pp| pp & k[1...k.size] == k[1...k.size]}.size == 1 ? p.each.with_index(1).select{|pp, i| pp & k[1...k.size] == k[1...k.size]}[0][1] : -1
end