#K8936. Smallest Team Covering All Required Skills

    ID: 37513 Type: Default 1000ms 256MiB

Smallest Team Covering All Required Skills

Smallest Team Covering All Required Skills

You are given a set of required skills and a list of employees, where each employee has a set of skills. Your task is to select the smallest team of employees such that their combined skills cover all the required skills. Formally, let \(R\) be the set of required skills and let each employee \(e_i\) have a skill set \(S_i\). You need to choose a subset of employees \(T\) such that:

$$ \bigcup_{e_i \in T} S_i \supseteq R $$

If no such team exists, output \(-1\). Otherwise, output the minimum number of employees required.

inputFormat

The input is given from standard input (stdin) in the following format:

  1. The first line contains two integers \(N\) and \(M\) separated by a space, where \(N\) is the number of employees and \(M\) is the number of required skills.
  2. The second line contains \(M\) integers representing the required skill IDs.
  3. The following \(N\) lines each begin with an integer \(k\) (the number of skills that the employee possesses) followed by \(k\) integers indicating the skill IDs of that employee.

outputFormat

Output a single integer to standard output (stdout): the minimum number of employees required to cover all required skills. If it is not possible to cover all required skills, output \(-1\).

## sample
4 3
1 2 3
2 1 2
1 3
1 2
2 2 3
2