while true
    n = gets.to_i
    break if n == 0
    arr = []
    n.times{arr << gets.chomp.split.map(&:to_i)}
    arr.map!{|ar| ar[1..-1]}
    divulged = gets.chomp.split.map(&:to_i)
    divulged.shift

    suspect = []
    arr.each_with_index{|ar, i| suspect <<  i + 1 if divulged - ar == []}
    puts (suspect.length == 1) ? suspect[0] : -1
end
