Supporting everyone

시간 제한0.25초메모리 제한1024 MB

문제

Alice is attending a sport event with many national teams and one thing is important to her: supporting every country.

There are $N$ countries represented and she has two ways to support a country: either have the flag drawn on her or have a pin with the name of the country. Alice has a list containing, for each country, the colours needed to make its flag. A total of $M$ colours that may appear across all flags and, in Alice’s list, each colour is conveniently represented as an integer between $1$ and $M$.

Each crayon and pin cost $1$, but her budget is tight. . . Can you help her find the minimum she can spend to support everyone?

입력

The first line contains the two space-separated numbers $N$ and $M$. Then follow $2N$ lines, grouped in pairs; the $(2i - 1)$th and $2i$th lines represent the $i$th country. More precisely, the $(2i - 1)$th line contains a single integer $k_i$: the number of colours in the flag of the $i$th country. Then, the $2i$th line contains $k_i$ space-separated numbers $c_{i,1}, c_{i,2}, \dots , c_{i,k_i}$; these are the colours in the flag of the $i$th country.

출력

The output should contain a single line, consisting of a single number: the minimum amount Alice can spend on crayons and pins to represent every country.

제한

  • $1 \le N \le 1\, 000$
  • $1 \le M \le 100$
  • $1 \le k_i \le M$ for all $i \le N$
  • $1 \le c_{i,j} \le M$ for all $i \le N$ and $j \le k_i$
  • for all $i \le N$, the $M$ colour numbers $c_{i,j}$ are pairwise distinct.