while n = gets.to_i
  break if n == 0
  g = n.times.map { gets.split.map(&:to_i)[1..-1] }
  t = gets.split.map(&:to_i)[1..-1]
  res = -1
  g.each_with_index do |l, i|
    if t.all?{ |v| l.include?(v) }
      if res == -1
        res = i + 1
      else
        res = -1
        break
      end
    end
  end
  p res
end