409728: GYM103708 J Jeffrey's ambition

Memory Limit:256 MB Time Limit:0 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

J. Jeffrey's ambitiontime limit per test0.3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

Jeffrey is the richest man in the world. In fact, he is so rich that he could buy all the major companies himself. Ordinary people don't like this, they wish every rich man was limited to having only one company.

The world council has listened to the requests of the people and has put the most important companies in the world up for sale. Each of the $$$N$$$ rich men in the world have given a list of the companies they would like to buy. The world council will be in charge of deciding which company will sell to each of the richest men.

Unfortunately, by meeting these conditions, it is possible for some companies to become ownerless. Which is terrible, since it is possible that Jeffrey take advantage of it and try to buy them, being thus, owners of more than one company.

People do not want this to happen, that is why the world council has given you the task of deciding which company to sell to each rich man, in such a way that at the end of the sale the minimum number of companies ends up without an owner.

Remember that rich men will only buy companies that are on their list.

Input

The first line contains two integers $$$N$$$ and $$$M$$$ ($$$1 \leq N,M \leq 10^4$$$) indicating respectively the number of rich men and the number of major companies. Each of the next $$$N$$$ lines describe each rich man list of companies. Each line starts with an integer $$$K$$$ ($$$0 \leq K \leq M$$$) indicating the number of companies he would like to buy, followed by $$$K$$$ integers $$$c_i$$$ ($$$1 \leq c_i \leq M$$$) for $$$i=1,2..K$$$ indicating the company he would like to buy.

It is guaranteed that the sum of $$$K$$$ does not exceed $$$10^5$$$.

Output

Output a single line with an integer indicating the minimum number of companies that will end up without an owner.

ExamplesInput
5 6
2 1 2
0
1 3
1 4
2 1 5
Output
2
Input
5 5
1 1
1 2
1 3
1 4
1 5
Output
0

加入题单

算法标签: