require 'set'
loop {
    n = gets.to_i
    break if n == 0
    a = []
    n.times do |i|
        l = gets.split.map(&:to_i)[1, 1000]
        a << Set.new(l)
    end
    l = Set.new(gets.split.map(&:to_i)[1, 1000])

    ans = (0...n).select{|i| l.subset?(a[i])}
    if ans.size == 1
        puts ans[0] + 1
    else
        puts -1
    end
}
