409728: GYM103708 J Jeffrey's ambition
Description
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.
InputThe 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$$$.
OutputOutput a single line with an integer indicating the minimum number of companies that will end up without an owner.
ExamplesInput5 6 2 1 2 0 1 3 1 4 2 1 5Output
2Input
5 5 1 1 1 2 1 3 1 4 1 5Output
0