cho.sh
Notes
Loading...

Barn Assignment

Time limit

2s

Memory limit

128 MB

Problem

Farmer John has built a barn and divided it into M stalls. To keep the barn comfortable, each stall can hold at most one cow.

At first, the cows were assigned arbitrarily, but a problem soon appeared. Each cow will enter only the stalls on its own preference list and refuses every other stall.

Given the list of stalls each cow is willing to enter, compute the maximum number of cows that can be assigned to stalls. Stalls are numbered from 1 to M.

Input

The first line contains N, the number of cows, and M, the number of stalls. (1 ≤ N, M ≤ 200)

Each of the next N lines describes one cow's preference list. For cow i, the line starts with S_i (0 ≤ S_i ≤ M), the number of stalls the cow is willing to enter, followed by S_i distinct stall numbers.

Output

Print the maximum number of cows that can be assigned to stalls.