P28792 [洛谷] [TJOI2018] Intelligence Competition
提高+
题目描述

Problem Description

Xiaodou has signed up for an intelligence competition and brought along $n$ friends as his support team to participate in the competition. The rules of the competition are as follows:

There are $m$ questions in total, and each person has one chance to answer a question. Each time a question is answered correctly, the participant can continue to answer the subsequent questions of that question until they answer a question incorrectly or there are no more subsequent questions.

Each question has a certain value. The reward a participant receives at the end of the competition is equivalent to the lowest value among the questions that the participant and their support team did not answer.

We know that Xiaodou and his support team are very strong and can solve all the questions in this competition.

Xiaodou wants to know, given the conditions of the questions and their subsequent questions, what is the maximum value he can achieve?

Input Format

The first line contains two integers $n, m$ ($n \leq 50, m \leq 500$).

The next $m$ lines, the $(i+1)$-th line describes the information for the question numbered $i$, in the format $v_i, k_i, a_{i,1}, a_{i,2}, ..., a_{i,k_i}$, where $v_i$ represents the value of the question, $k_i$ represents the number of subsequent questions, and $a_{i,1}, a_{i,2}, ..., a_{i,k_i}$ represent the numbers of the $k_i$ subsequent questions.

Output Format

If all questions can be answered correctly, output AK; otherwise, output the highest reward value Xiaodou can obtain.

Sample Input and Output

Sample Input #1

1 3
1 0
2 1 3
3 0

Sample Output #1

AK

Sample Input #2

1 6
1 2 2 3
2 1 4
3 1 4
4 1 6
5 0
6 0

Sample Output #2

5

Notes

For $10\%$ of the data, $1 < n, m \leq 10$.

For $20\%$ of the data, $1 < n, m \leq 100$.

For $100\%$ of the data, $1 < n \leq 50, 1 < m \leq 500, v_i \leq 10^9, k_i, a_{i,j} \leq m$.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
1 3 1 0 2 1 3 3 0
样例输出
AK