while true
  n = gets.to_i
  break if n == 0
  list = []
  n.times{
    array = []
    line = gets.split(" ").map{|e|e.to_i}
    array = line[1..line.length-1]if line[0] != 0
    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 if k == e&k
  }

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

end