while true
  n = gets.to_i
  break if n == 0
  list = []
  n.times{|t|
    array = []
    line = gets.split(" ").map{|e|e.to_i}
    array = line[1..line.length-1]if line[0] != 0
    #array.push t+1
    list.push array
  }
  k = gets.split(" ").map{|e|e.to_i}
  k = k[1..k.length-1]

  array = []
  list.each_with_index{|e,i|
    array.push i+1 if k == e&k
  }

  if array.length == 1
    puts array[0]
  else
    puts -1
  end
end