loop do
  n = gets.to_i
  break if n == 0

  pn = Array.new
  n.times do |i|
    m, *ps = gets.chomp.split.map &:to_i
    pn[i] = ps
  end
  k, *ks = gets.chomp.split.map &:to_i

  index = nil;
  num = 0
  pn.each_with_index do |ps, i|
    if ks.all? {|p| ps.include? p }
      index = i + 1
      num += 1
    end
  end
  puts num == 1 ? index : -1
end