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

	schedule = Array.new(30,0)
	(0..n-1).each{|i|
		gets.split(/\s+/).map(&:to_i)[1..-1].each{|day|
			schedule[day-1] |= (1 << i)
		}
	}

	x_day = -1
	(0..29).each{|d1|
		gathered = schedule[d1]
		(d1-1).downto(0){|d2|
			members = schedule[d2]
			gathered |= members if gathered & members > 0
		}
		if gathered + 1 == (1 << n)
			x_day = d1 + 1
			break
		end
	}

	puts x_day
}