Mr. Trasapong, the head of Computer Engineering Department, would like to have a meeting as soon as possible to address some issues of the department. However, other members in his department are so busy that it is very difficult to arrange their schedules for the meeting. So, in order to settle the meeting date, he requested every member to send back a list of convenient dates by E-mail. Your mission is to help him by writing a program that chooses the best date from the submitted lists. Your program should find the most convenient date for the most of the members. If there is more than one such day, the earliest is the best.
The input has multiple data sets, each starting with a line containing the number of members in the department and the quorum* of the meeting.
Here, N, meaning the number of the members in the department, and Q meaning the quorum, are positive integers. N is less than 20, and, of course, Q is less than or equal to N.
N lines follow, each describing convenient dates for a member in the following format.M Date1 Date2 ... DateM
Here, M means the number of convenient dates for the member, which is an integer greater than or equal to zero. The remaining items in the line are his/her dates of convenience, which are positive integers less than 31, that is, 1 means tomorrow, 2 means the day after tomorrow, and so on. They are in ascending order without any repetition and separated by a space character. Lines have neither leading nor trailing spaces.
A line containing two zeros indicates the end of the input.
For each data set, print a single line containing the date number convenient for the largest number of members. If there is more than one such date, print the earliest. However, if no dates are convenient for more than or equal to the quorum number of members, print 0 instead.
2 1 4
3 3 4 8
4 1 5 8 9
3 2 5 9
5 2 4 5 7 9
2 1 4
3 2 5 9
2 2 4
2 1 2
3 1 2 9
2 2 4
Note: quorum means the smallest number of the people who must present at a meeting.
用于NUPT ACM 2010 Personal Ranking Contest 5
本题由旧版NOJ导入，来源：ACM-ICPC Thailand Southern Area Programming Contest 2010