Under construction

Still being built. Things may change

Supporting everyone

Interview

Time limit0.25sMemory limit1024 MB

Summary
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.
Level

Medium5 of 10

Topics
Graph, BFS
Solved
No attempts yet

Problem

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

There are NN 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 MM colours that may appear across all flags, and in Alice's list each colour is an integer between 11 and MM.

Each crayon and pin costs 11. 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 NN and MM. Then follow 2N2N lines, grouped in pairs. The (2i−1)(2i-1)th line contains a single integer kik_i, the number of colours in the flag of the iith country. The 2i2ith line contains kik_i space-separated numbers ci,1,ci,2,…,ci,kic_{i,1}, c_{i,2}, \dots, c_{i,k_i}, the colours in the flag of the iith 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

  • 1≤N≤1 0001 \le N \le 1\,000
  • 1≤M≤1001 \le M \le 100
  • 1≤ki≤M1 \le k_i \le M for all i≤Ni \le N
  • 1≤ci,j≤M1 \le c_{i,j} \le M for all i≤Ni \le N and j≤kij \le k_i
  • For all i≤Ni \le N, the kik_i colour numbers ci,jc_{i,j} are pairwise distinct.

Examples2

  1. Example 1

    Input
    7 6
    3
    1 4 5
    3
    1 4 5
    3
    1 4 5
    3
    3 4 5
    3
    3 4 5
    3
    3 4 5
    3
    2 5 6
    
    Expected output
    5
    
  2. Example 2

    Input
    8 12
    2
    7 9
    12
    1 2 3 4 5 6 7 8 9 10 11 12
    2
    7 9
    2
    7 9
    3
    3 4 11
    2
    7 9
    2
    7 9
    2
    7 9
    
    Expected output
    4