天天看點

poj 1274 The Perfect Stall

description

farmer john completed his new barn just last week,

complete with all the latest milking technology. unfortunately, due to

engineering problems, all the stalls in the new barn are different. for the

first week, farmer john randomly assigned cows to stalls, but it quickly became

clear that any given cow was only willing to produce milk in certain stalls. for

the last week, farmer john has been collecting data on which cows are willing to

produce milk in which stalls. a stall may be only assigned to one cow, and, of

course, a cow may be only assigned to one stall. 

given the preferences

of the cows, compute the maximum number of milk-producing assignments of cows to

stalls that is possible. 

input

the input includes several cases. for each case,

the first line contains two integers, n (0 <= n <= 200) and m (0 <= m

<= 200). n is the number of cows that farmer john has and m is the number of

stalls in the new barn. each of the following n lines corresponds to a single

cow. the first integer (si) on the line is the number of stalls that the cow is

willing to produce milk in (0 <= si <= m). the subsequent si integers on

that line are the stalls in which that cow is willing to produce milk. the stall

numbers will be integers in the range (1..m), and no stall will be listed twice

for a given cow.

output

for each case, output a single line with a single

integer, the maximum number of milk-producing stall assignments that can be

made.

sample input

sample output