Supporting everyone
InterviewTime limit0.25sMemory limit1024 MB
Each country is either supported with a pin for 1 or has its flag colours bought at 1 per colour; find the minimum total cost.
Problem
Alice is attending a sport event with many national teams, and one thing is important to her: supporting every country.
There are countries represented. 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. There are colours that may appear across all flags, and in Alice's list each colour is an integer between and .
Each crayon and pin costs . Her budget is tight. Can you help her find the minimum she can spend to support everyone?
Input
The first line contains two space-separated numbers and . Then follow lines, grouped in pairs. The th line contains a single integer , the number of colours in the flag of the th country. The th line contains space-separated numbers , the colours in the flag of the th country.
Output
The output should contain a single line with a single number: the minimum amount Alice spends on crayons and pins to represent every country.
Constraints
- for all
- for all and
- For all , the colour numbers are pairwise distinct.