Miracle Tree#2433

Miracle Tree

1 second
256 megabytes
Easy

On one of the branches of the magic tree, a gardener has cultivated various types of fruits (such as bananas, oranges, etc.) and now wants to harvest them. He can pick two adjacent fruits, and immediately after he does so, a new fruit grows in the space between them. The type of this new fruit is determined entirely by the types of the two fruits that were picked.

Each time this operation is performed, the total number of fruits on the branch decreases by , so eventually there will be only one fruit left, which can no longer be picked. Your task is to determine what types of fruit this last remaining fruit can possibly be.

Input

The first line of the input file contains two integers and (1 \leq N \leq 500, 1 \leq k \leq 10), where is the number of fruits on the branch, and is the number of different types of fruits that can grow on the magic tree. The second line contains integers, indicating the types of fruits appearing in order on the branch. Each integer is between and . The next lines each contain integers, specifying the rules for growing new fruits: the -th number in the -th line indicates the type of fruit that grows if two consecutive fruits are picked, where the first fruit is of type and the second is of type .

Output

On a single line of the output file, print in ascending order the types of fruits that could possibly be the last remaining one on the branch of the magic tree.

Examples

Example 1

Loading
Loading