Cow Conundrum


Submit solution

Points: 1
Time limit: 2.0s
Python 5.0s
Memory limit: 256M

Author:
Problem type
Allowed languages
C, C++, Java, Python

Irhas is in charge of managing a herd of cows, and he is stressed out since many of them don't seem to be eating as much they should. He has n cows and m feeding troughs, and each cow will visit a subset of feeding troughs throughout the day. Irhas has bought some GoPros and wants to make sure he records every single interaction between a cow and a feeding trough.

If he puts a GoPro on a cow, it will capture every interaction between itself and all the troughs it visits. If he puts a GoPro on a feeding trough, it will capture its interactions with every cow that visits it. How many GoPros does Irhas need at minimum to cover every single cow/feeding trough interaction? These cameras are expensive and he wants to spend as little as possible.

It is possible for no cows to visit a trough, or a cow to visit no troughs, we regard these as having no interactions, and don't need to monitor them with cameras.

Input

The first line contains two integers n and m (1 \leq n,m \leq 10^5), the number of cows and the number of troughs, labelled 1\dots n and 1\dots m respectively.

The next 2n lines come in pairs, detailing the troughs each cow will visit. The first line of each pair contains a single number T_i (0 \leq T_i \leq m), the number of troughs the ith cow will visit throughout the day. The next line contains T_i space-separated integers t_j (1 \leq t_j \leq m), each trough that this cow will visit.

The trough numbers are unique in each line. The total number of cow/trough interactions (i.e., the sum of all T_is) will not exceed 5\times 10^5.

Output

Output the minimum number of cameras Irhas needs to buy to make sure every interaction between a cow and a trough is recorded. Irhas can either place the cameras on cows or on troughs, following the rules above.

Example

Input 1
3 3
2
1 2
1
3
1
3
Output 1
2

In this case, it is optimal to place a camera on cow 1, and on trough 3. This will ensure that all interactions are covered.

Input 2
4 5
3
1 4 5
1
2
2
2 3
1
3
Output 2
3

Here it is optimal to place cameras on cow 1, and troughs 2 and 3.


Comments

There are no comments at the moment.