Monocarp plays a computer game. In this game, he maintains a space empire. The empire is governed by $$$n$$$ political parties. Initially, every party has political power equal to $$$0$$$, and there is no ruling party.
During each of the next $$$m$$$ turns, the following happens:
Determine which party Monocarp has to support during each turn so that he doesn't lose the game due to the events, and the score he achieves is the maximum possible. Initially, Monocarp's score is $$$0$$$.
The first line contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n, m \le 50$$$) — the number of political parties and the number of turns, respectively.
The second line contains $$$m$$$ integers $$$p_1, p_2, \dots, p_m$$$ ($$$1 \le p_j \le n$$$), where $$$p_j$$$ is the index of the party which should be the ruling party at the end of the $$$j$$$-th turn.
Then $$$n$$$ lines follow. The $$$i$$$-th of them contains $$$m$$$ integers $$$a_{i,1}, a_{i,2}, \dots, a_{i,m}$$$ ($$$1 \le a_{i,j} \le 10^5$$$), where $$$a_{i,j}$$$ is the amount of points Monocarp gets if he supports the $$$i$$$-th party during the $$$j$$$-th turn.
If Monocarp loses the game no matter how he acts, print one integer $$$-1$$$.
Otherwise, print $$$m$$$ integers $$$c_1, c_2, \dots, c_m$$$ ($$$1 \le c_j \le n$$$), where $$$c_j$$$ is the index of the party Monocarp should support during the $$$j$$$-th turn. If there are multiple answers, print any of them.
2 32 1 21 2 34 5 6
2 1 2
3 51 1 1 2 11 1 1 1 110 5 7 8 157 10 9 8 15
1 3 2 2 1
3 51 1 1 1 11 1 1 1 110 5 7 8 157 10 9 8 15
-1
Название |
---|