#C8338. Collect All Cards

    ID: 52309 Type: Default 1000ms 256MiB

Collect All Cards

Collect All Cards

You are given a collection of card packs. Each pack contains a subset of cards numbered from 1 to n. John wants to collect all cards from 1 to n by buying as few packs as possible.

Your task is to determine the minimum number of packs John needs to purchase so that he collects every card from 1 to n. If it is impossible to collect all cards using the available packs, output -1.

The problem can be formulated as follows:

Given an integer \(n\) (the total number of distinct cards) and an integer \(m\) (the number of packs available), along with \(m\) packs where each pack contains some cards, find the minimum number of packs such that the union of cards in these packs is exactly \(\{1, 2, \dots, n\}\). If no such combination exists, output \(-1\).

inputFormat

The first line contains two integers n and m where \(1 \leq n \leq 50\) and \(1 \leq m \leq 15\).

The next m lines each describe a pack. Each line starts with an integer \(k\) representing the number of cards in the pack, followed by \(k\) integers denoting the card numbers in that pack.

The input is read from stdin.

outputFormat

Output a single integer representing the minimum number of packs needed to collect all cards from 1 to n. If it is not possible, output -1.

The output should be written to stdout.

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