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

	schedule = (0..29).map{[]}
	(0..n-1).each{|member|
		gets.split(/\s+/).map(&:to_i)[1..-1].each{|day|
			schedule[day-1] << member
		}
	}

	x_day = -1
	(0..29).each{|current_day|
		current_members = schedule[current_day]
		(current_day-1).downto(0){|old_day|
			old_members = schedule[old_day]
			if current_members & old_members != []
				current_members |= old_members
			end
		}
		if current_members.size == n
			x_day = current_day + 1
			break
		end
	}

	puts x_day
}