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

	know = (1..n).map{
		bits = 0
		gets.split.map(&:to_i)[1..-1].each{|i|
			bits |= (1 << i-1)
		}
		bits
	}

	leaked = 0
	gets.split.map(&:to_i)[1..-1].each{|i|
		leaked |= (1 << i-1)
	}

	candidate = []
	(0..n-1).each{|i|
		candidate << i+1 if know[i] & leaked == leaked
	}

	if candidate.size == 1
		p candidate[0]
	else
		p -1
	end
}