loop do
  n = gets.to_i
  break if n == 0
  m = []
  n.times do
    m << gets.split.map do |v|
      v.to_i - 1
    end[1..-1]
  end
  k = gets.split.map do |v|
    v.to_i - 1
  end[1..-1]

  suspects = []
  m.each_with_index do |ids, mi|
    suspected = true
    k.each do |target|
      unless ids.include? target
        suspected = false
        break
      end
    end

    suspects << mi + 1 if suspected
  end

  puts suspects.size == 1 ? suspects[0] : -1
end