QOJ.ac

QOJ

実行時間制限: 1 s メモリ制限: 256 MB 満点: 100

#14625. Intelligence Contest

統計

Xiao Dou has signed up for a quiz competition and brought $n$ friends along to form a team. The rules of the competition are as follows:

There are $m$ questions in total. Each person can answer one question. After answering a question, they can choose one of the subsequent questions of that question to answer, and so on, until they answer a question that has no subsequent questions.

Each question has a value. The final reward for the team is equal to the minimum value among all the questions that Xiao Dou and his friends have answered.

We now know the questions and the conditions for subsequent questions, and they are capable of answering all the questions in this competition.

Xiao Dou wants to know, given the questions and the subsequent question conditions, what is the maximum reward he can obtain?

Input

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

The next $m$ lines contain information about the questions, where the $(i+1)$-th line describes question $i$: The format is $v_i, k_i, a_{i,1}, a_{i,2}, \dots, a_{i,k_i}$, where $v_i$ is the value of the question, $k_i$ is the number of subsequent questions for this question, and $a_{i,1}, a_{i,2}, \dots, a_{i,k_i}$ are the indices of the $k_i$ subsequent questions.

Output

If all questions can be answered, output "AK". Otherwise, output the maximum reward Xiao Dou can obtain.

Examples

Input 1

1 3
1 0
2 1 3
3 0

Output 1

AK

Input 2

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

Output 2

5

Constraints

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

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.